Problem Source: http://www.cnblogs.com/del/archive/2008/10/25/1069523.html#1351197
Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) button1: tbutton; button2: tbutton; procedure alert (Sender: tobject); Procedure button1click (Sender: tobject); Procedure button2click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} uses mmsystem; {function for merging two WAV file streams} function conwavstream (awavstream1, awavstream2: tstream; var anewstream: tstream): Boolean; Type twavformat = packed record chunkid: array [0 .. 3] of ansichar; {'riff'} chunksize: longword; {size-8} format: array [0 .. 3] of ansichar; {'wave '} subchunk1id: array [0 .. 3] of ansichar; {'fmt'} subchunk1size: longword; {hex10} audioformat: word; {hex 01} numofchannels: word; {1 mono, 2 STEREO} samplerate: longword; {number of samples/sec} byterate: longword; {samplerate * num of channels * bytes per (Mono) Sample} bytespersample: word; {size of (Mono) Sample} bitspersample: word; {bytespersample * 8} subchunk2id: array [0 .. 3] of ansichar; {'data'} subchunk2size: longword; {number of data bytes} end; var vwavformat1: twavformat; vwavformat2: twavformat; vchunksize1, struct: integer; begin result: = false; If awavstream1.read (vwavformat1, sizeof (twavformat) Then exit; If awavstream2.read (vwavformat2, sizeof (twavformat) Then exit; if comment 'riff' then exit; If comment 'data' then exit; vchunksize1: = comment; vchunksize2: = comment; vwavformat1.chunksize: = 0; Comment: = 0; vwavformat2.chunksize: = 0; vwavformat2.subchunk2size: = 0; if not comparemem (@ vwavformat1, @ vwavformat2, sizeof (twavformat) Then exit; {different formats} vwavformat1.chunksize: = vchunksize1 + vchunksize2 + sizeof (vwavformat1)-8; vwavformat1.subchunk2size: = vchunksize1 + vchunksize2; anewstream. write (vwavformat1, sizeof (twavformat); anewstream. copyfrom (awavstream1, vchunksize1); anewstream. copyfrom (awavstream2, vchunksize2); Result: = true; end; {conwavstream end} var wavstream: tstream; {merge two resource streams; two wav files must be loaded in the resource respectively, and name them respectively: wav1, wav2} procedure tform1.formcreate (Sender: tobject); var RS1, rs2: tresourcestream; begin RS1: = tresourcestream. create (hinstance, 'wav1', rt_rcdata); rs2: = tresourcestream. create (hinstance, 'wav2', rt_rcdata); wavstream: = tmemorystream. create; conwavstream (RS1, rs2, wavstream); rs1.free; rs2.free; end; Procedure tform1.formdestroy (Sender: tobject); begin wavstream. free; end; {loop playback} procedure tform1.button1click (Sender: tobject); begin sndplaysound (tmemorystream (wavstream ). memory, snd_async or snd_memory or snd_loop); end; {pause} procedure tform1.button2click (Sender: tobject); begin sndplaysound (nil, 0); end.