/* TODO: there must be a check here to see if the audio device has been opened * successfuly. This is a bitch because it requires all 6 or 7 OS-specific functions * to be changed. Is anyone willing to do this at all??? */ int setup_audio(struct AUDIO_HEADER *header) { if (A_AUDIO_PLAY) { if (AUDIO_BUFFER_SIZE==0) audioOpen(t_sampling_frequency[header->ID][header->sampling_frequency], (header->mode!=3 && !A_DOWNMIX),A_SET_VOLUME); else bufferpid = audioBufferOpen(t_sampling_frequency[header->ID][header->sampling_frequency], (header->mode!=3 && !A_DOWNMIX),A_SET_VOLUME); } return 0; }
int decodeMPEG_2(int inFilefd) { struct AUDIO_HEADER header; int cnt,g,err=0; TControlMsg message; if ((in_file=fdopen(inFilefd,"r"))==NULL) { return(1); } append=data=nch=0; /* initialize globals */ GUI_STOPPED = FALSE; GUI_PLAYING = TRUE; GUI_FD_TO_PLAY = -1; for (cnt=0;;cnt++) { if ((g=gethdr(&header))!=0) { switch (g) { case GETHDR_ERR: die("error reading mpeg bitstream. exiting.\n"); break; case GETHDR_NS : warn("this is a file in MPEG 2.5 format, which is not defined\n"); warn("by ISO/MPEG. It is \"a special Fraunhofer format\".\n"); warn("amp does not support this format. sorry.\n"); break; case GETHDR_FL1: warn("ISO/MPEG layer 1 is not supported by amp (yet).\n"); break; case GETHDR_FF : warn("free format bitstreams are not supported. sorry.\n"); break; case GETHDR_SYN: warn("oops, we're out of sync.\n"); break; default: } break; } if (!(cnt%10)){ GUIstatusDisplay(cnt); } if(get_msg(&message) >= 0) { int pflag = 0; cnt = parse_msg(&message,&header,cnt); if (GUI_PAUSE) { int flags; pflag = 1; #if 0 /* Set stdin to blocking */ if((flags = fcntl(STDIN_FILENO, F_GETFL, 0)) < 0) perror("fcntl"); flags ^= O_NONBLOCK; if(fcntl(STDIN_FILENO, F_SETFL, flags) < 0) perror("fcntl"); #endif } while(GUI_PAUSE){ if(get_msg(&message) >= 0) cnt = parse_msg(&message,&header,cnt); } if (pflag) { int flags; /* Set stdin to non-blocking */ #if 0 if((flags = fcntl(STDIN_FILENO, F_GETFL, 0)) < 0) perror("fcntl"); flags |= O_NONBLOCK; if(fcntl(STDIN_FILENO, F_SETFL, flags) < 0) perror("fcntl"); #endif } if (GUI_STOP || (GUI_FD_TO_PLAY != -1)){ break; } } /* crc is read just to get out of the way. */ if (header.protection_bit==0) getcrc(); if (!cnt && A_AUDIO_PLAY) { /* setup the audio when we have the frame info */ if (AUDIO_BUFFER_SIZE==0) audioOpen(t_sampling_frequency[header.ID][header.sampling_frequency], (header.mode!=3), A_SET_VOLUME); else audioBufferOpen(t_sampling_frequency[header.ID][header.sampling_frequency],(header.mode!=3),A_SET_VOLUME); } if (layer3_frame(&header,cnt)) { warn(" error. blip.\n"); err=1; break; } } fclose(in_file); if (A_AUDIO_PLAY) if (AUDIO_BUFFER_SIZE!=0) audioBufferClose(); else audioClose(); else fclose(out_file); if (!(GUI_STOP) && (GUI_FD_TO_PLAY == -1)) { /* We've reached the end of the track, notify the jukebox... */ TControlMsg rmsg; rmsg.type = MSG_NEXT; rmsg.data = 0; send_msg(&rmsg, TRUE); } GUI_STOPPED = TRUE; GUI_PLAYING = FALSE; return(err); }