int PlayThread_file() { int k; if (buffercount > 0) { for (k = 0; k < (768*2 - buffercount); k++) buffer[k] = buffer[k + buffercount]; read_buffer_filestream(infile, buffer + (768*2) - buffercount, buffercount); buffercount = 0; } sample_buffer = (char*)faacDecDecode(hDecoder, &frameInfo, buffer, 768*2); if (frameInfo.error) { MessageBox(NULL, faacDecGetErrorMessage(frameInfo.error), "FAAD Error", MB_OK); last_frame = 1; } buffercount += frameInfo.bytesconsumed; bytecount += frameInfo.bytesconsumed; if (bytecount >= fileread) last_frame = 1; return frameInfo.bytesconsumed; }
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; }
static int read_ADIF_header(FILE_STREAM *file, faadAACInfo *info) { int bitstream; unsigned char buffer[ADIF_MAX_SIZE]; int skip_size = 0; int sf_idx; /* Get ADIF header data */ info->headertype = 1; if(read_buffer_filestream(file, buffer, ADIF_MAX_SIZE) < 0) return -1; /* copyright string */ if(buffer[0] & 0x80) skip_size += 9; /* skip 9 bytes */ bitstream = buffer[0 + skip_size] & 0x10; info->bitrate = ((unsigned int)(buffer[0 + skip_size] & 0x0F)<<19)| ((unsigned int)buffer[1 + skip_size]<<11)| ((unsigned int)buffer[2 + skip_size]<<3)| ((unsigned int)buffer[3 + skip_size] & 0xE0); if (bitstream == 0) { info->object_type = ((buffer[6 + skip_size]&0x01)<<1)|((buffer[7 + skip_size]&0x80)>>7); sf_idx = (buffer[7 + skip_size]&0x78)>>3; } else {
int aac_seek(int pos_ms, int *sktable) { double offset_sec; offset_sec = pos_ms / 1000.0; if (!current_file_mode) { seek_filestream(infile, sktable[(int)(offset_sec+0.5)], FILE_BEGIN); bytecount = sktable[(int)(offset_sec+0.5)]; buffercount = 0; read_buffer_filestream(infile, buffer, 768*2); } else { memmap_index = sktable[(int)(offset_sec+0.5)]; } return 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; }