Stupid Newbie Question

Started by SCGrant327,

SCGrant327

Could SOMEONE please give me an example of using BASS for the following:

I am trying to create a wav file in memory (dynamically) and then play it. I have been able to create a disk file, but when I try to make it only in memory, BASS only plays a 10th of a second of static.

I did not use BASS to create or play the disk file.

ANY help would be greatly appreciated!

Oh Yeah!....Borland C++ Builder 6....

DanaPaul


QuoteI am trying to create a wav file in memory (dynamically) and then play it.

Here is an example in (Pascal) Delphi that I clipped from somewhere on the Net.  I haven't had any chance to play with it yet, but maybe it will help you.  The purpose of this code is to play 2 distinct "beeps", as in acknowledgement of a completed task...


procedure Sound(Frequency, Duration : Integer);
var
 WaveFormatEx : TWaveFormatEx;
 MS : TMemoryStream;
 I, TempInt, DataCount, RiffCount : Integer;
 SoundValue : Byte;
 W : Double;

const
 Mono : Word = $0001;
 SampleRate : Integer = 11025; // 8000, 11025, 22050, or 44100
 RiffId : string = 'RIFF';
 WaveId : string = 'WAVE';
 FmtId : string = 'fmt ';
 DataId : string = 'data';
begin
 with WaveFormatEx do
 begin
   wFormatTag := WAVE_FORMAT_PCM;
   nChannels := Mono;
   nSamplesPerSec := SampleRate;
   wBitsPerSample := $0008;
   nBlockAlign := (nChannels * wBitsPerSample) div 8;
   nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
   cbSize := 0;
 end;
 MS := TMemoryStream.Create;
 with MS do
 begin
   {Calculate length of sound data and of file data}
   DataCount := (Duration *  SampleRate) div 1000;  // sound data
   RiffCount := Length(WaveId)
                + Length(FmtId) + SizeOf(DWord) + SizeOf(TWaveFormatEx)
                + Length(DataId) + SizeOf(DWord) + DataCount; // file data
   {write out the wave header}
   Write(RiffId[1], 4);                           // 'RIFF'
   Write(RiffCount, SizeOf(DWord));               // file data size
   Write(WaveId[1], Length(WaveId));              // 'WAVE'
   Write(FmtId[1], Length(FmtId));                // 'fmt '
   TempInt := SizeOf(TWaveFormatEx);
   Write(TempInt, SizeOf(DWord));                 // TWaveFormat data size
   Write(WaveFormatEx, SizeOf(TWaveFormatEx));    // WaveFormatEx record
   Write(DataId[1], Length(DataId));              // 'data'
   Write(DataCount, SizeOf(DWord));               // sound data size
   {calculate and write out the tone signal}      // now the data values
   w := 2 * Pi * Frequency;  // omega
   for i := 0 to DataCount - 1 do begin
     SoundValue := 127 + trunc(127 * sin(i * w / SampleRate)); // wt = w * i /SampleRate
     Write(SoundValue, SizeOf(Byte));
   end;
   {now play the sound}
   sndPlaySound(MS.Memory, SND_MEMORY or SND_SYNC);
   MS.Free;
 end;
end;


An example of use...

Sound(1200, 1000);
Sound(2400, 1000);