int play(char *fn) { int maxlatency; int thread_id; HANDLE input_file = INVALID_HANDLE_VALUE; unsigned output_bits_per_sample; if(0 == decoder_) { return 1; } input_file = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(input_file == INVALID_HANDLE_VALUE) { return -1; } CloseHandle(input_file); if(!safe_decoder_init_(fn, decoder_)) { return 1; } #ifdef FLAC__DO_DITHER output_bits_per_sample = min(file_info_.bits_per_sample, 16); #else output_bits_per_sample = file_info_.bits_per_sample; #endif strcpy(lastfn_, fn); paused_ = 0; decode_pos_ms_ = 0; seek_needed_ = -1; wide_samples_in_reservoir_ = 0; maxlatency = mod_.outMod->Open(file_info_.sample_rate, file_info_.channels, output_bits_per_sample, -1, -1); if(maxlatency < 0) { /* error opening device */ return 1; } /* dividing by 1000 for the first parameter of setinfo makes it */ /* display 'H'... for hundred.. i.e. 14H Kbps. */ mod_.SetInfo((file_info_.sample_rate*file_info_.bits_per_sample*file_info_.channels)/1000, file_info_.sample_rate/1000, file_info_.channels, 1); /* initialize vis stuff */ mod_.SAVSAInit(maxlatency, file_info_.sample_rate); mod_.VSASetInfo(file_info_.sample_rate, file_info_.channels); mod_.outMod->SetVolume(-666); /* set the output plug-ins default volume */ killDecodeThread = 0; thread_handle = (HANDLE) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) DecodeThread, (void *) &killDecodeThread, 0, &thread_id); return 0; }
void FLAC_XMMS__play_file(char *filename) { FILE *f; sample_buffer_first_ = sample_buffer_last_ = 0; audio_error_ = false; stream_data_.abort_flag = false; stream_data_.is_playing = false; stream_data_.is_http_source = is_http_source(filename); stream_data_.eof = false; stream_data_.play_thread_open = false; stream_data_.has_replaygain = false; if(!is_http_source(filename)) { if(0 == (f = fopen(filename, "r"))) return; fclose(f); } if(decoder_ == 0) return; if(!safe_decoder_init_(filename, decoder_)) return; if(stream_data_.has_replaygain && flac_cfg.output.replaygain.enable) { if(flac_cfg.output.resolution.replaygain.bps_out == 8) { stream_data_.sample_format = FMT_U8; stream_data_.sample_format_bytes_per_sample = 1; } else if(flac_cfg.output.resolution.replaygain.bps_out == 16) { stream_data_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE; stream_data_.sample_format_bytes_per_sample = 2; } else { /*@@@ need some error here like wa2: MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 8/16-bit samples\n", "ERROR: plugin can only handle 8/16-bit samples", 0); */ fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", flac_cfg.output.resolution.replaygain.bps_out); safe_decoder_finish_(decoder_); return; } } else { if(stream_data_.bits_per_sample == 8) { stream_data_.sample_format = FMT_U8; stream_data_.sample_format_bytes_per_sample = 1; } else if(stream_data_.bits_per_sample == 16 || (stream_data_.bits_per_sample == 24 && flac_cfg.output.resolution.normal.dither_24_to_16)) { stream_data_.sample_format = (is_big_endian_host_) ? FMT_S16_BE : FMT_S16_LE; stream_data_.sample_format_bytes_per_sample = 2; } else { /*@@@ need some error here like wa2: MessageBox(mod_.hMainWindow, "ERROR: plugin can only handle 8/16-bit samples\n", "ERROR: plugin can only handle 8/16-bit samples", 0); */ fprintf(stderr, "libxmms-flac: can't handle %d bit output\n", stream_data_.bits_per_sample); safe_decoder_finish_(decoder_); return; } } FLAC__replaygain_synthesis__init_dither_context(&stream_data_.dither_context, stream_data_.sample_format_bytes_per_sample * 8, flac_cfg.output.resolution.replaygain.noise_shaping); stream_data_.is_playing = true; if(flac_ip.output->open_audio(stream_data_.sample_format, stream_data_.sample_rate, stream_data_.channels) == 0) { audio_error_ = true; safe_decoder_finish_(decoder_); return; } stream_data_.title = flac_format_song_title(filename); flac_ip.set_info(stream_data_.title, stream_data_.length_in_msec, stream_data_.sample_rate * stream_data_.channels * stream_data_.bits_per_sample, stream_data_.sample_rate, stream_data_.channels); stream_data_.seek_to_in_sec = -1; stream_data_.play_thread_open = true; pthread_create(&decode_thread_, NULL, play_loop_, NULL); }