void main(void){ char input[10] = {0}; char in = 0; int count = 0; long output = 50; while(1){ in = getchar(); if(in == 'u'){ if(++output < 102){ SetAlsaMasterVolume(output); printf("output: %d\n",output); } else{ output = 102; printf("output: MAX\n",output); } } else if(in == 'd'){ if(--output >= 0){ SetAlsaMasterVolume(output); printf("output: %d\n",output); } else{ output = 0; printf("output: %d\n",output); } } } return; }
/*Function Name: setVolume Description: Called to navigate in the volume menu*/ void setVolume() { char flag = 1; ssize_t bytes; char rbuffer[4]; while (flag) { if (mute == 0) menuApp(volume + 10); else menuApp(21); bytes = read(f, rbuffer, sizeof(rbuffer)); if (rbuffer[1] >= 4) mute = 1; else mute = 0; if (rbuffer[0] == 2) { if (volume > 0) volume--; } else if (rbuffer[0] == 1) { if (volume < 10) volume++; } else if (rbuffer[1]&0x01 == 1) { if (mute == 0) SetAlsaMasterVolume(volume*10); else SetAlsaMasterVolume(0); flag = 0; menuApp(3); } } }
void * process_evdev_events(void ) { int evdev_fd; struct input_event ev[64]; int clic_duration; int i; int static_brightness = 0x80; int pulse_speed = 255; int pulse_table = 0; int pulse_asleep = 1; int pulse_awake = 0; evdev_fd = find_powermate(O_WRONLY); if(evdev_fd < 0){ fprintf(stderr, "Unable to locate powermate\n"); return 1; } pulse_awake=1; powermate_pulse_led(static_brightness, pulse_speed, pulse_table, pulse_asleep, pulse_awake); if ((evdev_fd = open("/dev/input/by-id/usb-Griffin_Technology__Inc._Griffin_PowerMate-event-if00", O_RDONLY)) < 0) { perror("jukebox"); return 1; } printf("Starting thread loop\n"); for (;;) { int rd = read(evdev_fd, ev, sizeof(struct input_event) * 64); if (rd < (int) sizeof(struct input_event)) { perror("\njukebox: error reading"); pthread_exit(NULL); } for (i = 0; i < rd / sizeof(struct input_event); i++){ if ( ev[i].type == 1 ) { if ( ev[i].value == 1 ) { clic_start_time=ev[i].time.tv_sec * 1000000 + ev[i].time.tv_usec; } else { clic_duration=( ev[i].time.tv_sec * 1000000 + ev[i].time.tv_usec - clic_start_time ) /1000; printf("That's a release, duration %ld ms\n", clic_duration ); if ( clic_duration > 3000 ) { sync(); // reboot(RB_POWER_OFF); } else if ( clic_duration > 500 ) { printf ("That was a long clic!\n"); } else { printf ("That was a short clic!\n"); media_toggle_playback(); } } } else if ( ev[i].type == 2 ) { SetAlsaMasterVolume(ev[i].value); last_scroll_event=ev[i].time.tv_sec * 1000000 + ev[i].time.tv_usec; } if(0) { printf("EventC: time %ld.%06ld, type %d (%s), code %d, value %d\n", ev[i].time.tv_sec, ev[i].time.tv_usec, ev[i].type, events[ev[i].type] ? events[ev[i].type] : "?", ev[i].code, ev[i].value); } } } printf("Thread loop finished\n"); close(evdev_fd); pthread_exit(NULL); }
/*Function Name: main Description: Main function*/ int main(int argc, char **argv) { char rbuffer[512]; int menu; int ret; ssize_t bytes; char openApp = 0; menu = 1; volume = 10; mute = 0; freq = 4; f = open("/dev/control0", O_RDWR, 0666); if (f == -1) { printf("failed to open control0.\n"); return 1; } while (openApp == 0) { printf("Presiona Enter para continuar\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); bytes = read(f, rbuffer, sizeof(rbuffer)); if (rbuffer[1]&0x01 == 1) openApp = 1; } while (openApp) { menuApp(menu); bytes = read(f, rbuffer, sizeof(rbuffer)); if (rbuffer[0] == 2) { if (menu > 1) menu--; } else if (rbuffer[0] == 1) { if (menu < 5) menu++; } else if (rbuffer[1]&0x01 == 1) { switch (menu) { case 1: if (mute == 1) SetAlsaMasterVolume(0); else SetAlsaMasterVolume(volume*10); play((freq*8000), "ex"); break; case 2: if (mute == 1) SetAlsaMasterVolume(0); else SetAlsaMasterVolume(volume*10); record((freq*8000), "ex"); break; case 3: setVolume(); break; case 4: setFrequency(); break; case 5: openApp = 0; printf("Thank you, Good bye MOFO\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); usleep(1000000); break; } } if (rbuffer[1] >= 4) mute = 1; else mute = 0; } close(f); }
///////////////////////////////////////////////////////////////////// // Starts up soundcard output thread using soundcard at list OutDevIndx ///////////////////////////////////////////////////////////////////// bool CSoundOut::Start(int OutDevIndx, bool StereoOut, double UsrDataRate, bool BlockingMode) { QAudioDeviceInfo DeviceInfo; long mvolume; m_StereoOut = StereoOut; m_BlockingMode = BlockingMode; //Get required soundcard from list m_OutDevices = DeviceInfo.availableDevices(QAudio::AudioOutput); if (-1 == OutDevIndx) GetAlsaMasterVolume(&mvolume); qDebug()<<"Soundcard volume" << mvolume; if (-1 == OutDevIndx) m_OutDeviceInfo = QAudioDeviceInfo::defaultOutputDevice(); else m_OutDeviceInfo = m_OutDevices.at(OutDevIndx); #if 1 //RRK get a list of audio devices and the default foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) { qDebug() << "l:" << deviceInfo.deviceName(); } QAudioDeviceInfo info = QAudioDeviceInfo::defaultOutputDevice(); qDebug() << "res:" << info.deviceName(); #endif //Setup fixed format for sound ouput m_OutAudioFormat.setCodec("audio/pcm"); //m_OutAudioFormat.setFrequency(SOUNDCARD_RATE); m_OutAudioFormat.setSampleRate(SOUNDCARD_RATE); m_OutAudioFormat.setSampleSize(16); m_OutAudioFormat.setSampleType(QAudioFormat::SignedInt); m_OutAudioFormat.setByteOrder(QAudioFormat::LittleEndian); if(m_StereoOut) //RRK m_OutAudioFormat.setChannels(2); m_OutAudioFormat.setChannelCount(2); else m_OutAudioFormat.setChannelCount(1); m_pAudioOutput = new QAudioOutput(m_OutDeviceInfo, m_OutAudioFormat, this); if(!m_pAudioOutput) { qDebug()<<"Soundcard output error"; return false; } if(QAudio::NoError == m_pAudioOutput->error() ) { //initialize the data queue variables m_UserDataRate = 1; //force user data rate to be changed ChangeUserDataRate(UsrDataRate); m_pOutput = m_pAudioOutput->start(); //start QT AudioOutput //RRK workaround for default, for some reason choosing default //sets the master volume to max! if (-1 == OutDevIndx) SetAlsaMasterVolume(50); //determine how long to sleep between low level reads based on samplerate and period size m_BlockTime = ( 250*m_pAudioOutput->periodSize() )/ ( SOUNDCARD_RATE*m_OutAudioFormat.channelCount() ); //RRK ( SOUNDCARD_RATE*m_OutAudioFormat.channels() ); //qDebug()<<"periodSize "<<m_pAudioOutput->periodSize(); //qDebug()<<"BlockTime "<<m_BlockTime; m_ThreadQuit = FALSE; start(QThread::HighestPriority); //start worker thread and set its priority // start(QThread::TimeCriticalPriority); //start worker thread and set its priority return true; } else { qDebug()<<"Soundcard output error"; return false; } }
void alsa_driver_do_command(unsigned char play_record, char *file_to_open, unsigned int sample_freq, unsigned int volume, unsigned char samplingTimeInSec) { unsigned int direction, status, size; unsigned long loops; char *buffer; FILE *id; snd_pcm_t *handle; snd_pcm_hw_params_t *params; snd_pcm_uframes_t frames; SetAlsaMasterVolume(volume*10); frames = 32; printf("Opening %s...\n", file_to_open); if (play_record == 0) id = fopen(file_to_open, "r"); else id = fopen(file_to_open, "w"); printf("file open\n"); printf("Opening device driver...\n"); if (id != 0) { if (play_record == 0) { status = snd_pcm_open(&handle, "default", SND_PCM_STREAM_PLAYBACK, 0); } else if (play_record == 1) { status = snd_pcm_open(&handle, "default", SND_PCM_STREAM_CAPTURE, 0); } else if (play_record != 1 || play_record != 0) { printf("ERROR occured while opening device driver.\n"); return; } if (status < 0) { printf("ERROR occured while opening device driver.\n"); exit(1); } printf("Device open\n"); /* Allocate a hardware parameters object. */ snd_pcm_hw_params_alloca(¶ms); /* Fill it in with default values. */ snd_pcm_hw_params_any(handle, params); /* Set the desired hardware parameters. */ /* Interleaved mode */ snd_pcm_hw_params_set_access(handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); /* Signed 16-bit little-endian format */ snd_pcm_hw_params_set_format(handle, params, SND_PCM_FORMAT_S16_LE); /* Two channels (stereo) */ snd_pcm_hw_params_set_channels(handle, params, 2); /* sample_freq bits/second sampling rate */ snd_pcm_hw_params_set_rate_near(handle, params, &sample_freq, &direction); /* Set period size to 32 frames. */ frames = 32; snd_pcm_hw_params_set_period_size_near(handle, params, &frames, &direction); /* Write the parameters to the driver */ printf("Setting hardware driver..\n"); status = snd_pcm_hw_params(handle, params); if (status < 0) { fprintf(stderr, "unable to set hw parameters: %s\n", snd_strerror(status)); exit(1); } printf("hardware parameters loaded correctly\n"); /* Use a buffer large enough to hold one period */ snd_pcm_hw_params_get_period_size(params, &frames, &direction); size = frames * 4; /* 2 bytes/sample, 2 channels */ buffer = (char *) malloc(size); /* We want to loop for samplingTimeInSec seconds */ snd_pcm_hw_params_get_period_time(params, &sample_freq, &direction); loops = 1000000 / sample_freq; loops *= samplingTimeInSec; printf("Hardware ready\n"); while (loops > 0) { loops--; if (play_record == 0) { status = fread(buffer, size, 1, id); if (status == 0) { printf("End of file\n"); break; } status = snd_pcm_writei(handle, buffer, frames); if (status == -EPIPE) { printf("overrun occurred\n"); snd_pcm_prepare(handle); } else if (status < 0) { printf("Error while writing\n"); } } else { status = snd_pcm_readi(handle, buffer, frames); if (status == -EPIPE) { printf("overrun occurred\n"); snd_pcm_prepare(handle); } else if (status < 0) { printf("Error while reading."); } status = fwrite(buffer, size, 1, id); } } printf("closing device..\n"); snd_pcm_drain(handle); snd_pcm_close(handle); printf("Releasing memory..\n"); free(buffer); fclose(id); } else { printf("Error while accesing file."); } }