BUG DESCRIPTION:
----------------
wavrite raises EXCEPTION_ACCESS_VIOLATION with mput
ERROR LOG:
----------
Warning !!!
Scilab has found a critical error (EXCEPTION_ACCESS_VIOLATION)
with "mput" function.
Save your data and restart Scilab.
Warning: stack problem..., cleared.
HOW TO REPRODUCE THE BUG:
-------------------------
stacksize(223739903);
s=ones([1:12345678])/2;
wavwrite(s, 44100, 16, 'test.wav');
OTHER INFORMATION:
------------------
I found this basic issue in Scilab for the last 15 to 20 years, but finally
decided to get to the bottom of it and when I got the error below asking me
to report the bug, I decided to do so. I found this issue in version 5.4.0.
I upgraded to Scilab 5.5.0 and produced the results here in that version.
This bug might be the same as 11291 which may have been closed because of
insufficient information. Please contact me if I can help.
PC and OS information:
Windows Vista Home Premium, Service Pack 1
Manufacturer: Gateway
Model: DX4200-09
Processor: AMD Phenom(tm) 9150e Quad-Core Processor 1.80 GHz
RAM: 4.00 GB
System type: 64-bit Operating System
To work around this bug, I tried writing code in scilab to create the wav file, but
found a similar issue when using a for loop. The bug can be avoided using a while loop.
//====================== code #2 =============================
stacksize(223739903);
s=ones([1:12345678])/2;
for i=[1:12345678]
printf("%d\n",s(i));
end;
//----------------------- error log #2 ----------------------------
Warning !!!
Scilab has found a critical error (EXCEPTION_ACCESS_VIOLATION)
with "mprintf" function.
Save your data and restart Scilab.
!--error 115
Stack problem detected within a loop.
A primitive function has been called with a wrong number of output arguments.
No output argument test has been made for this function.
Please report this bug :
http://bugzilla.scilab.org/
//====================== code #3: runs without error =============================
stacksize(223739903);
s=ones([1:12345678])/2;
i=1;
while i<=12345678
printf("%d\n",s(i));
i=i+1;
end;
//====================== code #4: runs without error =============================
//for others trying to write wave files before this bug is fixed may find this code helpful.
//
// I put mono wave data in s[]
sSize=size(s);
if int(sSize(2)/2)*2 == sSize(2) then
//s already has an even number of elements
else
s=[x 0];
end
//Now write the file. see http://www.sonicspot.com/guide/wavefiles.html
fd = mopen('MyFirstFile.wav','wb',0);
[err,msg] = merror(fd)
if (err <> 0) then
printf('Problem opening file:%s\n',msg);
else
mputstr("RIFF",fd); //sGroupID = RIFF
mput(sSize(2)*2+4+20+8,'ui',fd); //dwFileLength following WAVE = Data.dwChunkSize + 4 + 20 + 8
mputstr("WAVE",fd); //sRiffType
//Format Chunk with a total size of 20 bytes
mputstr("fmt ",fd); //sGroupID
mput(16,'ui',fd); //ChunkSize the size of what follows; so dwChunkSize and sGroupID don't contribute to this.
mput(1,'us',fd); //wFormatTag
mput(1,'us',fd); //wChannels. 1= mono
mput(44100,'ui',fd); //dwSamplesPerSec. CD audio of 44.1kHz
mput(88200,'ui',fd); //dwAvgBytesPerSec = sampeRate * blockAlign
mput(2,'us',fd); //wBlockAlign = wChannels * (dwBitsPerSample/8)
mput(16,'us',fd); //dwBitsPerSample .
//Data Chunk
mputstr("data",fd); //sGroupID
mput(sSize(2)*2,'ui',fd); //dwChunkSize = number of elements in the sample data = dwSamplesPerSec * wChannels * duration of audio in seconds
scale = (32759)/(max(abs(s))); //using 32759 instead of 32760 to reduce the chance of exceeding wave file extremes.
i=1;
while(i<=sSize(2))
mput(int(s(i)*scale),'us',fd);
if (i/100000)==int(i/100000) then
printf("."); //to help me know the program is still running.
end
i=i+1;
end
end; //if fd
mclose(fd);