' Investigate JG's audio file ' Peter Rice 03/04/17 ' Non-unpacking version ' This program corrects errors in samples 0 and 2 bit 22, ' but ignores errors in samples 0 and 2 bit 6 (almost inaudible), ' and samples 1 and 3 bit 14 (audible but no comparison data for correction). ' Note that the simple corrections in this version of the program ' work only for audio data less than -12dBFS. ' Adjust these paths to appropriate file names as necessary. var name$:="c:\\users\\peter.ced\\downloads\\samplecopy.wav"; var name2$:="c:\\users\\peter.ced\\downloads\\samplecopy output2.wav"; 'use an input block size divisible by 3 for efficiency var data%[768], header%[11], out%[3]; var nsize%:=768; var r%, n%, fr%, fw%; var s%:=0; Seconds(0); ' zero the time ' Open the input and output file, halting if something goes wrong fr%:=fileopen(name$,9, 0); if(fr% < 0) then message("Could not open read file"); halt; endif; 'open file for writing fw%:=fileopen(name2$,9, 1); if(fw% < 0) then message("Could not open write file"); halt; endif; 'Copy the .wav header (44 bytes) from input file to output file r%:= view(fr%).BReadSize(-4,header%); r%:= view(fw%).BWriteSize(4,header%); 'Now process the blocks of data 'Each block of 3 (32-bit) words holds 4 (24-bit) samples repeat r%:= view(fr%).BReadSize(-4,data%); ' returns no. of words read for n%:= 0 to r%-3 step 3 do ' loop not executed if r% came back as 0 ' operate on 24-bit audio samples 0 and 2 to make bit 22 same as bit 23 ' samples 1 and 3 unchanged out%[0]:= (data%[n%] band 0xffbfffff) bor ((data%[n%] band 0x00800000)/2); ' sample 0 bit 22 out%[1]:= data%[n%+1]; out%[2]:= (data%[n%+2] band 0xffffffbf) bor ((data%[n%+2] band 0x00000080)/2); ' sample 2 bit 22 view(fw%).BWriteSize(4,out%[]); ' write the result data next; until r% <= 0; 'stop when all read s%:=Seconds(); ' get elapsed time message("That run took ", s%," seconds"); ' Clean up FileClose(fr%); FileClose(fw%);