axStatus axFile::openAppend ( const char* filename, bool create_if_file_not_exists ) { int flag = O_RDWR; if( create_if_file_not_exists ) flag |= O_CREAT; axStatus st; st = _os_open( filename, flag ); if( !st ) return st; setPosEnd(0); return 0; }
axStatus axFile::openAppend ( const wchar_t* filename, bool create_if_file_not_exists ) { DWORD access_flag = GENERIC_READ | GENERIC_WRITE; DWORD create_flag = create_if_file_not_exists ? OPEN_ALWAYS : OPEN_EXISTING; axStatus st; st = _os_open( filename, access_flag, create_flag ); if( !st ) return st; setPosEnd(0); return 0; }
axStatus axFile::openWrite( const wchar_t* filename, bool create_if_file_not_exists, bool truncate ) { DWORD access_flag = GENERIC_READ | GENERIC_WRITE; DWORD create_flag = 0; if( truncate ) { if( create_if_file_not_exists ) { create_flag = CREATE_ALWAYS; }else{ create_flag = OPEN_EXISTING | TRUNCATE_EXISTING; } }else{ if( create_if_file_not_exists ) { create_flag = OPEN_ALWAYS; }else{ create_flag = OPEN_EXISTING; } } return _os_open( filename, access_flag, create_flag ); }
axStatus axFile::openRead ( const wchar_t* filename ) { DWORD access_flag = GENERIC_READ; DWORD create_flag = OPEN_EXISTING; return _os_open( filename, access_flag, create_flag ); }
axStatus axFile::openRead ( const char* filename ) { return _os_open( filename, O_RDONLY ); }
axStatus axFile::openWrite ( const char* filename, bool create_if_file_not_exists, bool truncate ) { int flag = O_RDWR; if( create_if_file_not_exists ) flag |= O_CREAT; if( truncate ) flag |= O_TRUNC; return _os_open( filename, flag ); }
int main(int argc, char **argv){ char *bufout; char *bufin; path_id path,devpath; error_code error; u_int32 bufsize_out = OUT_BUF_SIZE; u_int32 bufsize_in = IN_BUF_SIZE; u_int32 count; int inlen,outlen; char *compbuf=NULL; int compbuflen=0,compbufpos=0; int status=MP3_OK; int i; struct mpstr mp; int iflag=0; if (argc != 3) { printf("Play MP3 file\n"); printf("Usage: mpgplay <filename><device>\n"); exit(1); } /* set up signal handler */ intercept (sighand); /* Initialize the MP3 decoder */ InitMP3(&mp); if ((error = _os_open(argv[1], FAM_READ, &path)) != SUCCESS) { return error; } /* Prepare the Sound device */ if ((error = _os_open(argv[2], FAM_WRITE, &devpath)) != SUCCESS) { return error; } if ((error = _os_srqmem (&bufsize_in, (void**)&bufin, 0)) != SUCCESS) { return error; } if ((error = _os_srqmem (&bufsize_out, (void**)&bufout, 0)) != SUCCESS) { return error; } sigval = SMAP_DONE_SIG; /* Sound is free */ #if defined(SHOW_TIME_INFO) time (&initial_time); #endif while(status != MP3_ERR){ count = IN_BUF_SIZE; /* read the data */ if ((error = _os_read(path, bufin, &count)) != SUCCESS){ if (error == EOS_EOF) break; /* done */ else return error; } inlen = count; /* Initialize buffer */ outlen = compbufpos = compbuflen = 0; status = decodeMP3(&mp,bufin,inlen,bufout,OUT_BUF_SIZE,&outlen); if (!iflag){ printf("Playing %s [%s - %dkbs]\n", argv[1], mp.fr.stereo?"Stereo":"Mono", frequencies[mp.fr.sampling_frequency]); #if defined(SHOW_FRAME) printf("FRAME: stereo %d jsbound %d single %d lsf %d\n", mp.fr.stereo, mp.fr.jsbound, mp.fr.single, mp.fr.lsf); printf("mpeg25 %d header_change %d lay %d error_protection %d\n", mp.fr.mpeg25, mp.fr.header_change, mp.fr.lay, mp.fr.error_protection); printf("bitrate_index %d sampling_frequency %d padding %d extension %d\n", mp.fr.bitrate_index, mp.fr.sampling_frequency, mp.fr.padding, mp.fr.extension); printf("mode %d mode_ext %d copyright %d original %d\n", mp.fr.mode, mp.fr.mode_ext, mp.fr.copyright, mp.fr.original); printf("emphasis %d framesize %d\n", mp.fr.emphasis, mp.fr.framesize); #endif iflag=1; } while(status == MP3_OK){ /* Check buffer size */ if ((compbufpos + outlen) > compbuflen || compbuf == NULL) { compbuflen = compbufpos+outlen; compbuf = (char *) realloc(compbuf,compbuflen); } memcpy(compbuf+compbufpos,bufout,outlen); compbufpos+=outlen; status = decodeMP3(&mp,NULL,0,bufout,OUT_BUF_SIZE,&outlen); } if (compbufpos) { int blks = compbufpos / SND_BLK_SIZE; int residual = compbufpos - (blks*SND_BLK_SIZE); #if defined(SHOW_TIME_INFO) { time (¤t_time); ts_time_decompose ( (unsigned long)difftime (current_time, initial_time)); total_blks += (blks+1); } #endif /* Wait for buffer slot to empty */ sigmask(1); if (sigval != SMAP_DONE_SIG){ tsleep(0); } else sigmask(-1); sigval = 0; if (compbufpos > sound_buffer_size) { sound_buffer = (u_char *) realloc(sound_buffer,compbufpos); } sound_buffer_size = compbufpos; memcpy(sound_buffer,compbuf,sound_buffer_size); /* * Fill up the sound maps */ for(i=0;i<blks;i++) { smap[i].num_channels = mp.fr.stereo; smap[i].sample_rate = frequencies[mp.fr.sampling_frequency]; smap[i].coding_method = CODING_METHOD; smap[i].sample_size = SAMPLE_SIZE; smap[i].cur_offset = 0; smap[i].loop_start = 0; smap[i].loop_count = 1; smap[i].loop_counter = 0; smap[i].next = &smap[i+1]; smap[i].trig_mask = 0; smap[i].trig_signal = 0; /* get the size of the data in this read */ smap[i].buf_size = smap[i].loop_end = SND_BLK_SIZE; smap[i].buf = &sound_buffer[i*SND_BLK_SIZE]; } /* If we do not have residual then back up to last sound map 1st */ if (residual==0) i--; /* Last block in chain */ smap[i].num_channels = mp.fr.stereo; smap[i].sample_rate = frequencies[mp.fr.sampling_frequency]; smap[i].coding_method = CODING_METHOD; smap[i].sample_size = SAMPLE_SIZE; smap[i].cur_offset = 0; smap[i].loop_start = 0; smap[i].loop_count = 1; smap[i].loop_counter = 0; smap[i].next = NULL; smap[i].trig_mask = SND_TRIG_READY; smap[i].trig_signal = SMAP_DONE_SIG; /* get the size of the data in this read */ smap[i].buf_size = smap[i].loop_end = residual?residual:SND_BLK_SIZE; smap[i].buf = &sound_buffer[i*SND_BLK_SIZE]; if ((error = _os_ss_snd_play(devpath, &smap[0], SND_NOBLOCK )) != SUCCESS) { return error; } compbufpos = 0; } } #if defined(SHOW_TIME_INFO) printf("\n"); #endif /* Wait for buffer slot to empty */ sigmask(1); if (sigval != SMAP_DONE_SIG){ tsleep(0); } else sigmask(-1); /* Exit the MP3 decoder */ ExitMP3(&mp); _os_srtmem(bufsize_in, (void *)bufin); _os_srtmem(bufsize_out, (void *)bufout); }