Page 2 of 2

PostPosted: August 2nd, 2006, 6:51 pm
by Johnny_Bit
can you try using streams and datapointers? It's safer and less problematic.

PostPosted: August 2nd, 2006, 7:21 pm
by Sonicfire1980
If anyone´s interested (attention: newbie code ;)):
http://www.prodyon-virtual-gear.com/wrongcode.jpg

@Johnny_Bit: yes? then i should take a closer look at tmemorystream and the like. have to learn all that first, i´m afraid :)

PostPosted: August 2nd, 2006, 8:15 pm
by Sonicfire1980


As you see,not much code, but obviously something must be total wrong :?

PostPosted: August 3rd, 2006, 11:10 am
by very angry mobster
Have you seen Tobybear's wavefile save/load units?WaveIOX.


vam

PostPosted: August 3rd, 2006, 12:40 pm
by Johnny_Bit
vam: give it rest, sonic is close to his own solution, so why waste such effort?

PostPosted: August 3rd, 2006, 1:04 pm
by Sonicfire1980
@vam: yes i know of this unit :) but i hope i´m able to do it alone and without it :wink: My problem is just - the last "test" in my code JPG ... the rest is working fine :?

PostPosted: August 3rd, 2006, 3:03 pm
by Sonicfire1980
So why on earth has no one an idea??
:shock: :lol:

PostPosted: August 3rd, 2006, 10:06 pm
by Sonicfire1980
Procedure TForm1.ProcessWave(FileName: String);
var
Wavbuffer: TSmallIntArray;
Header: TWaveHeader;
i: Integer;
Amp: Double;

begin
Amp := 0.5; // half the volume
LoadTheWave(Outputfile.Text, Wavbuffer, sizeOf(Header)+1); //laden der audio daten
for i := 0 to High(Wavbuffer) do
begin
Wavbuffer[i] := Floor(Wavbuffer[i]*Amp);
end;
SaveTheWave(Outputfile.Text, Wavbuffer, sizeOf(Header)+1);
end;

result: almost white noise in the wav file ... does someone know why? (that worked in my old code before i switched to filestreams) :?:

If i use e.g. Amp := 2 it correctly doubles the output volume - why doesn´t the other way around work?

PostPosted: August 4th, 2006, 12:11 pm
by Kambiz
I just want to remind you that SmallInt has 2 bytes length.

PostPosted: August 4th, 2006, 6:57 pm
by Sonicfire1980
Thanks, Kambiz - i already found the problem , it was because the "+1"! :)

However, anoterh little thing that is scarping my head... am i missing something here? :) :

I want to append a block (50%) of reversed audio data at the end of my main buffer:
Code: Select all
WavEnd := High(Wavbuffer) div 2;


Code: Select all
      begin
          WavAdd := High(Wavbuffer);
          setlength(TempWavbuffer, WavAdd+WavEnd);

          // copy the whole main buffer into temp buffer
          for i := Low(TempWavbuffer) to WavAdd do
          begin
                TempWavbuffer[i] := Wavbuffer[i];
          end;

          // append 50% of main buffer at end
          for i := Low(TempWavbuffer) to WavEnd do
          begin
                TempWavbuffer[WavAdd+i] := Wavbuffer[WavEnd+i];
          end;
       end


Is this a wrong way to try that? Besides this i'm trying to update the
header with the correct length information like so:
Code: Select all
Header.DataBytes := Header.DataBytes + Header.DataBytes div 2;


...but obviously here's something wrong, either it crashes or the WAV files has an "invalid file size"!
:oops:

Any ideas ? :)

PostPosted: August 4th, 2006, 7:54 pm
by Kambiz
Windows has a set of APIs for manipulating RIFF files (name of these functions start with mmIO). Why you don't use these functions?

PostPosted: August 4th, 2006, 8:03 pm
by Sonicfire1980
Kambiz wrote:Windows has a set of APIs for manipulating RIFF files (name of these functions start with mmIO). Why you don't use these functions?


Hmm...dont know, that would mean i would have to rewrite everything the third time ;)