•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 455,985 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,795 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 1284 | Replies: 2
![]() |
•
•
Join Date: Dec 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
Please...i ask helping from..all ....
i want to write sound value from dinamic array,,to save in .wav type...
i tried to write header .wav and result it i think is true...
but i still confused how way to write sound value..
i put sound value in array, name is hasil_wav,,,
i take example i want write for wav 16 bit mono in DELPHI 7.0
please help me....
my listing like this...
procedure TForm1.Button4Click(Sender: TObject);
var
// chan, frq, vl : DWORD; Tmp: Integer;
// buf : array [0..10000] of BYTE;
// BytesRead : integer;
temp : string;
i : longint;
RecStream : TFileStream;
nChannels : Word; // number of channels (i.e. mono, stereo, etc.)
nSamplesPerSec : DWORD; // sample rate
nAvgBytesPerSec : DWORD; // transfer rata-rata per detik
nBlockAlign : Word;
wBitsPerSample : Word; // number of bits per sample of mono data
// FileName : String;
begin
nChannels := 1;
wBitsPerSample := 16;
nBlockAlign := nChannels * wBitsPerSample div 8;
//BASS_ChannelGetAttributes(chan, frq, vl, Tmp);
nSamplesPerSec := 22050;
nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
// FileName := ExtractFileName(SourceFileName);
// FileName := Copy(FileName, 1, Length(FileName) - Length(ExtractFileExt(FileName)));
// RecStream := TFileStream.Create(OutPath + FileName + '.wav', fmCreate);
RecStream := TFileStream.Create('Cinta.wav',fmCreate);
// Write header portion of wave file
temp := 'RIFF';
RecStream.write(temp[1], length(temp));
temp := #0#0#0#0;
RecStream.write(temp[1], length(temp)); // File size: to be updated
temp := 'WAVE';
RecStream.write(temp[1], length(temp));
temp := 'fmt ';
RecStream.write(temp[1], length(temp));
temp := #$10#0#0#0;
RecStream.write(temp[1], length(temp)); // Fixed
temp := #1#0;
RecStream.write(temp[1], length(temp)); // PCM format
if nChannels = 1 then
temp := #1#0
else
temp := #2#0;
RecStream.write(temp[1], length(temp));
RecStream.write(nSamplesPerSec, 2);
temp := #0#0;
RecStream.write(temp[1], length(temp)); // SampleRate is given as dWord
RecStream.write(nAvgBytesPerSec, 4);
RecStream.write(nBlockAlign, 2);
RecStream.write(wBitsPerSample, 2);
temp := 'data';
RecStream.write(temp[1],length(temp));
temp := #0#0#0#0;
RecStream.write(temp[1],length(temp)); // Data size: to be updated
// RecStream.Write(buf, SizeOf(Buf));
{complete WAV header
Rewrite some fields of header }
i := RecStream.Size - 8; // size of file
RecStream.Position := 4;
RecStream.write(i, 4);
i := i - $24; // size of data
RecStream.Position := 40;
RecStream.write(i, 4);
RecStream.Free;
end;
i want to write sound value from dinamic array,,to save in .wav type...
i tried to write header .wav and result it i think is true...
but i still confused how way to write sound value..
i put sound value in array, name is hasil_wav,,,
i take example i want write for wav 16 bit mono in DELPHI 7.0
please help me....
my listing like this...
procedure TForm1.Button4Click(Sender: TObject);
var
// chan, frq, vl : DWORD; Tmp: Integer;
// buf : array [0..10000] of BYTE;
// BytesRead : integer;
temp : string;
i : longint;
RecStream : TFileStream;
nChannels : Word; // number of channels (i.e. mono, stereo, etc.)
nSamplesPerSec : DWORD; // sample rate
nAvgBytesPerSec : DWORD; // transfer rata-rata per detik
nBlockAlign : Word;
wBitsPerSample : Word; // number of bits per sample of mono data
// FileName : String;
begin
nChannels := 1;
wBitsPerSample := 16;
nBlockAlign := nChannels * wBitsPerSample div 8;
//BASS_ChannelGetAttributes(chan, frq, vl, Tmp);
nSamplesPerSec := 22050;
nAvgBytesPerSec := nSamplesPerSec * nBlockAlign;
// FileName := ExtractFileName(SourceFileName);
// FileName := Copy(FileName, 1, Length(FileName) - Length(ExtractFileExt(FileName)));
// RecStream := TFileStream.Create(OutPath + FileName + '.wav', fmCreate);
RecStream := TFileStream.Create('Cinta.wav',fmCreate);
// Write header portion of wave file
temp := 'RIFF';
RecStream.write(temp[1], length(temp));
temp := #0#0#0#0;
RecStream.write(temp[1], length(temp)); // File size: to be updated
temp := 'WAVE';
RecStream.write(temp[1], length(temp));
temp := 'fmt ';
RecStream.write(temp[1], length(temp));
temp := #$10#0#0#0;
RecStream.write(temp[1], length(temp)); // Fixed
temp := #1#0;
RecStream.write(temp[1], length(temp)); // PCM format
if nChannels = 1 then
temp := #1#0
else
temp := #2#0;
RecStream.write(temp[1], length(temp));
RecStream.write(nSamplesPerSec, 2);
temp := #0#0;
RecStream.write(temp[1], length(temp)); // SampleRate is given as dWord
RecStream.write(nAvgBytesPerSec, 4);
RecStream.write(nBlockAlign, 2);
RecStream.write(wBitsPerSample, 2);
temp := 'data';
RecStream.write(temp[1],length(temp));
temp := #0#0#0#0;
RecStream.write(temp[1],length(temp)); // Data size: to be updated
// RecStream.Write(buf, SizeOf(Buf));
{complete WAV header
Rewrite some fields of header }
i := RecStream.Size - 8; // size of file
RecStream.Position := 4;
RecStream.write(i, 4);
i := i - $24; // size of data
RecStream.Position := 40;
RecStream.write(i, 4);
RecStream.Free;
end;
Last edited by delphinew : Dec 2nd, 2007 at 11:01 pm.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
I've never needed to play with wav files myself, so I know nothing about it.
However, you could easily have googled this.
Hope this helps.
However, you could easily have googled this.
Hope this helps.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Pascal and Delphi Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Convert .wav file into bytes (HTML and CSS)
- .wav file on x86 (Assembly)
- Play a .wav file (Java)
- could someone write.. (C++)
- which language ? (Computer Science and Software Design)
- wav file problem (Visual Basic 4 / 5 / 6)
- Audio File Matching Program (C++)
- Big Game need progrmmers (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: a simple one bar for using a percentage movement
- Next Thread: trying to use one form to open another form



Linear Mode