void setGVolume(int volume) { int temp; if (left >= right) { temp = left / right; VsSetVolume(volume, (int)(volume*temp)); } else { temp = right / left; VsSetVolume((int)(volume*temp), volume); } }
void playTone(){ VsPlayerInit(); VsSetVolume(1, 1); VsBeepStart(2500); NutSleep(1000); VsBeepStop(); return 1; }
/*-----functions-----*/ THREAD(tone, arg){ VsPlayerInit(); VsSetVolume(1, 1); VsBeepStart(2500); NutSleep(1000); VsBeepStop(); NutThreadExit(); NutThreadKill(); NutThreadDestroy(); }
THREAD(FallingAsleep, arg) { printf("falling asleep started\n"); for(;;) { int volumeGoal = 254; //Dont start yet if no sound is playing while(VsGetStatus() != VS_STATUS_RUNNING) NutSleep(50); //Get the amount of seconds from the fallingAsleepTime minutes long totalSeconds = (long)fallingAsleepTime * 1000 * 60; printf("totalseconds = %lu\n", totalSeconds); //Get the time to sleep before "increasing" the volume. Divide the totalSeconds by the volumeGoal to get a smooth transition long sleepTime = totalSeconds / volumeGoal; printf("sleeptime = %lu\n", sleepTime); int currentVolume = VsGetVolume(); //"Increase" the volume until it hits the goal while(currentVolume < volumeGoal) { NutSleep(sleepTime); VsSetVolume(currentVolume + 1, currentVolume + 1); printf("Falling Asleep Mode tick now. Volume lowered %d", VsGetVolume()); currentVolume++; } //Call stopStream in network.c stopStream(); //Turn off falling asleep mode fallingAsleepMode = 0; //Reset volume VsSetVolume(0, 0); //Exit the thread NutThreadExit(); } }
THREAD(AlarmPollingThread, arg) { static u_int button_cooldown_counter = 0; static bool button_cooldown = true; u_long alarm_a; u_long alarm_b; short snooze_time; tm snooze; tm alarm_a_backup; for(;;) { X12RtcGetStatus(&alarm_a); alarm_b = alarm_a; alarm_a &= 0b00100000; alarm_b &= 0b01000000; if(alarm_a!=0 && alarm_a_on) { VsBeep((u_char)500, 1000); //BeepBoop, beeps with (frequency, duration) VsSetVolume(0,0); puts("Volume on"); } if(alarm_b!=0 && alarm_b_on) { VsBeep((u_char)1000, 1000); //BeepBoop, beeps with (frequency, duration) VsSetVolume(0,0); puts("Volume on"); } if(button_cooldown_counter >= 2) { button_cooldown = false; button_cooldown_counter = 0; } if(kb_button_is_pressed(KEY_ALT) && alarm_a!=0) { At45dbPageRead(2, &snooze_time, 2); X12RtcClearStatus(0b00100000); get_alarm_a(&snooze); snooze.tm_min+=snooze_time; set_alarm_a(&snooze); } if(!button_cooldown) { switch(kb_button_pressed()) { case KEY_ESC: puts("escape pressed"); if(VsGetVolume() != 0) { puts("volume on"); VsSetVolume(0, 0); } else if(VsGetVolume() == 0) { puts("volume off"); VsSetVolume(100, 100); } if(alarm_a != 0) { X12RtcClearStatus(0b00100000); At45dbPageRead(3, &alarm_a_backup, sizeof(tm)); set_alarm_a(&alarm_a_backup); } if(alarm_b != 0) { X12RtcClearStatus(0b01000000); disable_alarm_b(); alarm_b_on = false; } break; case KEY_01: alarm_a_on = !alarm_a_on; alarmstatus_changed = true; break; case KEY_02: alarm_b_on = !alarm_b_on; alarmstatus_changed = true; break; default: break; } button_cooldown = true; } if(button_cooldown) button_cooldown_counter++; NutSleep(100); } }
/* * \brief Play MP3 stream. * * \param stream Socket stream to read MP3 data from. */ void PlayMp3Stream(FILE *stream, u_long metaint) { size_t rbytes; u_char *mp3buf; u_char ief; int got = 0; u_long last; u_long mp3left = metaint; /* * Initialize the MP3 buffer. The NutSegBuf routines provide a global * system buffer, which works with banked and non-banked systems. */ if (NutSegBufInit(8192) == 0) { puts("Error: MP3 buffer init failed"); return; } /* * Initialize the MP3 decoder hardware. */ if (VsPlayerInit() || VsPlayerReset(0)) { puts("Error: MP3 hardware init failed"); return; } VsSetVolume(0, 0); /* * Reset the MP3 buffer. */ ief = VsPlayerInterrupts(0); NutSegBufReset(); VsPlayerInterrupts(ief); last = NutGetSeconds(); for (; ;) { if(STOP_THREAD){ STOP_THREAD = 0; return; } /* * Query number of byte available in MP3 buffer. */ ief = VsPlayerInterrupts(0); mp3buf = NutSegBufWriteRequest(&rbytes); VsPlayerInterrupts(ief); /* * If the player is not running, kick it. */ if (VsGetStatus() != VS_STATUS_RUNNING) { if (rbytes < 1024 || NutGetSeconds() - last > 4UL) { last = NutGetSeconds(); puts("Kick player"); VsPlayerKick(); } } /* * Do not read pass metadata. */ if (metaint && rbytes > mp3left) { rbytes = mp3left; } /* * Read data directly into the MP3 buffer. */ while (rbytes) { if ((got = fread(mp3buf, 1, rbytes, stream)) > 0) { ief = VsPlayerInterrupts(0); mp3buf = NutSegBufWriteCommit(got); VsPlayerInterrupts(ief); if (metaint) { mp3left -= got; if (mp3left == 0) { ProcessMetaData(stream); mp3left = metaint; } } if (got < rbytes && got < 512) { printf("%lu buffered\n", NutSegBufUsed()); NutSleep(250); } else { NutThreadYield(); } } else { break; } rbytes -= got; } if (got <= 0) { break; } NutSleep(100); } }
void setAudioVolume(int vol) { VsSetVolume(vol, vol); soundVolume = vol; }