* simplify mp3 conversions
    - test for file access using fopen
    - use linear sample rate converter
This commit is contained in:
David Freese 2020-01-14 23:14:01 -06:00
parent f754c087a5
commit 524e5f2b35
3 changed files with 23 additions and 33 deletions

View file

@ -15720,7 +15720,6 @@ i.e. localhost"));
o->end();
} // Fl_Group* o
{ Fl_Value_Slider2* o = sldrAlertVolume = new Fl_Value_Slider2(256, 325, 403, 20, _("Alert volume"));
sldrAlertVolume->tooltip(_("My transmit CW WPM"));
sldrAlertVolume->type(1);
sldrAlertVolume->box(FL_DOWN_BOX);
sldrAlertVolume->color(FL_BACKGROUND_COLOR);
@ -15729,10 +15728,9 @@ i.e. localhost"));
sldrAlertVolume->labelfont(0);
sldrAlertVolume->labelsize(14);
sldrAlertVolume->labelcolor(FL_FOREGROUND_COLOR);
sldrAlertVolume->minimum(5);
sldrAlertVolume->maximum(100);
sldrAlertVolume->step(1);
sldrAlertVolume->value(50);
sldrAlertVolume->value(20);
sldrAlertVolume->textsize(14);
sldrAlertVolume->callback((Fl_Callback*)cb_sldrAlertVolume);
sldrAlertVolume->align(Fl_Align(FL_ALIGN_RIGHT));

View file

@ -7423,7 +7423,7 @@ progdefaults.changed=true;}
}
}
Fl_Group grpRigCat {
label {Rig Control/CAT (rigcat)} selected
label {Rig Control/CAT (rigcat)}
xywh {200 0 600 350} box ENGRAVED_BOX align 21 hide
code0 {CONFIG_PAGE *p = new CONFIG_PAGE(o, _("Rig Control/CAT (rigcat)"));}
code1 {config_pages.push_back(p);}
@ -8477,7 +8477,7 @@ progdefaults.changed = true;}
}
}
Fl_Group {} {
label {Soundcard/Alerts} open
label {Soundcard/Alerts} open selected
xywh {200 0 600 350} box ENGRAVED_BOX color 50 selection_color 50 align 21 hide
code0 {CONFIG_PAGE *p = new CONFIG_PAGE(o, _("Soundcard/Alerts"));}
code1 {config_pages.push_back(p);}
@ -8800,7 +8800,7 @@ progdefaults.TIMED_OUT_ALERT_MENU = o->value();} open
label {Alert volume}
callback {progdefaults.alert_volume = (int)o->value();
progdefaults.changed = true;}
tooltip {My transmit CW WPM} xywh {256 325 403 20} type Horizontal align 8 minimum 5 maximum 100 step 1 value 50 textsize 14
xywh {256 325 403 20} type Horizontal align 8 maximum 100 step 1 value 20 textsize 14
code0 {o->value(progdefaults.alert_volume);}
code1 {o->labelsize(FL_NORMAL_SIZE); o->textsize(FL_NORMAL_SIZE);}
class Fl_Value_Slider2

View file

@ -155,7 +155,6 @@ void process_alert()
* syncs to requests for audio alert output
**********************************************************************************/
static c_portaudio *requester = 0;
//static c_portaudio *stream_requester = 0;
static void * alert_loop(void *args)
{
@ -185,12 +184,6 @@ static void * alert_loop(void *args)
if (alert_process_flag == TERMINATE)
break;
// execute a single request for audio stream processing
// if (stream_ready) {
// stream_requester->process_mon();
// stream_ready = false;
// }
}
return (void *)0;
}
@ -278,8 +271,8 @@ static void add_alert(c_portaudio * _cpa, float *buffer, int len, int src)
if(alert_thread_running) {
if (_cpa->paStreamParameters.device == -1) return;
struct PLAYLIST *plist = new PLAYLIST;
plist->fbuff = buffer;//new float[len];
plist->bufflen = len; // # floats
plist->fbuff = buffer;
plist->bufflen = len;
plist->cpa = _cpa;
plist->data_ptr = 0;
plist->frames = len / _cpa->paStreamParameters.channelCount;
@ -539,15 +532,15 @@ void c_portaudio::play_mp3(std::string fname)
{
if (fname.empty()) return;
drmp3_config config;
drmp3_uint64 frame_count;
drmp3 mp3;
if (!drmp3_init_file(&mp3, fname.c_str(), NULL)) {
LOG_ERROR("Failed to open mp3 file");
FILE* pFile;
pFile = fopen(fname.c_str(), "rb");
if (pFile == NULL) {
return;
}
drmp3_uninit(&mp3);
fclose(pFile);
drmp3_config config;
drmp3_uint64 frame_count;
float* mp3_buffer = drmp3_open_file_and_read_f32(
fname.c_str(), &config, &frame_count );
@ -557,11 +550,10 @@ void c_portaudio::play_mp3(std::string fname)
return;
}
LOG_VERBOSE("\n\
MP3 parameters\n\
channels: %d\n\
sample rate: %d\n\
frame count: %ld\n",
LOG_INFO("\n\
MP3 channels: %d\n\
sample rate: %d\n\
frame count: %ld\n",
config.outputChannels,
config.outputSampleRate,
long(frame_count));
@ -609,6 +601,7 @@ void c_portaudio::do_play_file(std::string fname)
{
if ((fname.find(".mp3") != std::string::npos) ||
(fname.find(".MP3") != std::string::npos)) {
//std::cout << "do_play_file(" << fname << ")" << std::endl;
return play_mp3(fname);
}
if ((fname.find(".wav") != std::string::npos) ||
@ -621,6 +614,7 @@ void c_portaudio::do_play_file(std::string fname)
void c_portaudio::play_file(std::string fname)
{
guard_lock filelock(&filelist_mutex);
//std::cout << "filelist.push(this, " << fname << ")" << std::endl;
filelist.push( FILELIST(this, fname));
}
@ -728,16 +722,14 @@ static void * filelist_loop(void *args)
MilliSleep(50);
if (filelist_terminate_flag) break;
if (!filelist.empty()) {
{
guard_lock filelock(&filelist_mutex);
{
guard_lock filelock(&filelist_mutex);
if (!filelist.empty()) {
fl = filelist.top();
filelist.pop();
fl.cpa->do_play_file(fl.fn);
}
fl.cpa->do_play_file(fl.fn);
}
}
return (void *)0;
}