int play_memmap(char *fn) { int tagsize = 0; infile = open_filestream(fn); if (infile == NULL) return 1; fileread = filelength_filestream(infile); memmap_buffer = (char*)LocalAlloc(LPTR, fileread); read_buffer_filestream(infile, memmap_buffer, fileread); /* skip id3v2 tag */ memmap_index = id3v2_tag(memmap_buffer); hDecoder = faacDecOpen(); /* Copy the configuration dialog setting and use it as the default */ /* initialize the decoder, and get samplerate and channel info */ if ((buffercount = faacDecInit(hDecoder, memmap_buffer + memmap_index, fileread - memmap_index - 1, &samplerate, &channels)) < 0) { MessageBox(mod.hMainWindow, "Error opening input file\n", "FAAD Error", MB_OK); return 1; } memmap_index += buffercount; PlayThread_memmap(); return 0; }
void seek_filestream(FILE_STREAM *fs, unsigned long offset, int mode) { if(fs->http) { return; } SetFilePointer(fs->stream, offset, NULL, mode); if(mode == FILE_CURRENT) fs->file_offset += offset; else if(mode == FILE_END) fs->file_offset = filelength_filestream(fs) + offset; else fs->file_offset = offset; fs->buffer_length = 0; fs->buffer_offset = 0; }
int play_file(char *fn) { int k; int tagsize; ZeroMemory(buffer, 768*2); infile = open_filestream(fn); if (infile == NULL) return 1; fileread = filelength_filestream(infile); buffercount = bytecount = 0; read_buffer_filestream(infile, buffer, 768*2); tagsize = id3v2_tag(buffer); /* If we find a tag, run right over it */ if(tagsize) { if(infile->http) { int i; /* Crude way of doing this, but I believe its fast enough to not make a big difference */ close_filestream(infile); infile = open_filestream(fn); for(i=0; i < tagsize; i++) read_byte_filestream(infile); } else { seek_filestream(infile, tagsize, FILE_BEGIN); } bytecount = tagsize; buffercount = 0; read_buffer_filestream(infile, buffer, 768*2); } hDecoder = faacDecOpen(); /* Copy the configuration dialog setting and use it as the default */ /* initialize the decoder, and get samplerate and channel info */ if((buffercount = faacDecInit(hDecoder, buffer, 768*2, &samplerate, &channels)) < 0) { MessageBox(mod.hMainWindow, "Error opening input file\n", "FAAD Error", MB_OK); return 1; } if(buffercount > 0) { bytecount += buffercount; for (k = 0; k < (768*2 - buffercount); k++) buffer[k] = buffer[k + buffercount]; read_buffer_filestream(infile, buffer + (768*2) - buffercount, buffercount); buffercount = 0; } PlayThread_file(); return 0; }