[Stk] RtAudio - Read entire file to memory
TJF
tjfoerster at web.de
Tue Mar 30 02:48:03 PDT 2010
Hi,
I cannot find the solution for my problem: I want to read an entire
raw-file to memory and play it. My example here is the basic playraw.cpp.
The problem is, that the new code (s.below the replaced code) could be
compiled without any problem (i.e. Win) and the program starts without
problem and it ends without any problems. But it ends immediately. It
does not play anything. If I do any SLEEP, I can see that the entire
file is loaded to memory, but will not be played.
Any idea?
Thanks a lot.
Regards
Thomas
FORMAT RTAUDIO_SINT16
// -------- original section rawplay.cpp - beginning
-------------------------------------------------------------------------------------------------------------
/*
OutputData data;
data.fd = fopen( file, "rb" );
if ( !data.fd ) {
std::cout << "Unable to find or open file!\n";
exit( 1 );
}
*/
// -------- original - end
---------------------------------------------------------------------------------------------------------------------
// -------- replaced code - beginning
-------------------------------------------------------------------------------------------------------
OutputData data;
int Size;
void *buffer;
size_t result;
data.fd = fopen ( file , "rb" );
std::cout << "\ndata.fd1 " << data.fd << std::endl;
if (data.fd==NULL) {
std::cout << "Unable to find or open file!\n";
exit (1);
}
fseek (data.fd , 0 , SEEK_END);
Size = ftell (data.fd);
buffer = calloc (Size,1);
std::cout << "\nbuffer: " << buffer << std::endl;
if (buffer == NULL) {
std::cout << "Memory error!\n";
exit (2);
}
rewind (data.fd);
result = fread (buffer,1,Size,data.fd);
std::cout << "\ndata.fd2 " << data.fd << std::endl;
if (result != Size) {
std::cout << "Reading error!\n";
exit (3);
}
// -------- replaced code - end
-------------------------------------------------------------------------------------------------------
More information about the Stk
mailing list