void audio_init(void) { vs_rst(1); delay_m(100); vs_spi_open(); delay_m(200); audio_reset(); delay_m(50); AUDIO_FIFO_INIT(); //audio_sin_test(); vs_vol=DEFAULT_VOLUME; vs_sbamp=DEFAULT_BASSAMP; vs_sbfreq=DEFAULT_BASSFREQ; vs_stamp=DEFAULT_TREBLEAMP; vs_stfreq=DEFAULT_TREBLEFREQ; audio_set_volume(vs_vol); vs_setbassfreq(vs_sbfreq); vs_setbassamp(vs_sbamp); vs_settreblefreq(vs_stfreq); vs_settrebleamp(vs_stamp); }
void audio_ldm_resume(void *data) { audio_state_t *state = data; audio_stream_t *is = state->input_stream; audio_stream_t *os = state->output_stream; if (AUDIO_ACTIVE(state) && state->hw_init) state->hw_init(state->data); if (os && os->dma_regs) { DMA_RESET(os); audio_reset(os); wake_up(&os->wq); } if (is && is->dma_regs) { DMA_RESET(is); audio_reset(is); wake_up(&is->wq); } }
void audio_clear(audio_t *a) { if(a->flags & SOURCE_DISK) munmap(a->prbuf, a->prbuf_size * sizeof(audio_sample_t)); else free(a->prbuf); a->prbuf = NULL; a->prbuf_size = 0; a->prbuf_offset = 0; a->flags &= ~SOURCE_DISK; audio_reset(a); }
int audio_close(snd_type snd) { oss_info dp = get_oss_info(snd); if (dp->thread) audio_reset(snd); if (dp->audio_fd) { close(dp->audio_fd); dp->audio_fd = 0; } free(dp->buffer); dp->buffer = 0; free((void *)snd->u.audio.descriptor); return SND_SUCCESS; }
void audio_discard_buf(audio_stream_t * s) { FN_IN; /* ensure DMA isn't using those buffers */ audio_reset(s); if (s->buffers) { int frag; for (frag = 0; frag < s->nbfrags; frag++) { if (!s->buffers[frag].master) continue; dma_free_coherent(NULL, s->buffers[frag].master, s->buffers[frag].data, s->buffers[frag].dma_addr); } kfree(s->buffers); s->buffers = NULL; } FN_OUT(0); }
static void audio_discard_buf(audio_stream_t * s) { DPRINTK("audio_discard_buf\n"); /* ensure DMA isn't using those buffers */ audio_reset(s); if (s->buffers) { int frag; for (frag = 0; frag < s->nbfrags; frag++) { if (!s->buffers[frag].master) continue; consistent_free(s->buffers[frag].data, s->buffers[frag].master, s->buffers[frag].dma_addr); } kfree(s->buffers); s->buffers = NULL; } }
int audio_init (int samplerate, float framerate) { /* Shutdown first */ audio_shutdown(); /* Clear the sound data context */ memset(&snd, 0, sizeof (snd)); /* Default settings */ snd.sample_rate = samplerate; snd.frame_rate = framerate; /* Calculate the sound buffer size (for one frame) */ snd.buffer_size = (int)(samplerate / framerate) + 32; /* SN76489 stream buffers */ snd.psg.buffer = (int16 *) malloc(snd.buffer_size * sizeof(int16)); if (!snd.psg.buffer) return (-1); /* YM2612 stream buffers */ snd.fm.buffer = (int32 *) malloc(snd.buffer_size * sizeof(int32) * 2); if (!snd.fm.buffer) return (-1); #ifndef NGC /* Output buffers */ snd.buffer[0] = (int16 *) malloc(snd.buffer_size * sizeof(int16)); snd.buffer[1] = (int16 *) malloc(snd.buffer_size * sizeof(int16)); if (!snd.buffer[0] || !snd.buffer[1]) return (-1); #endif /* Resampling buffer */ if (config.hq_fm && !Fir_Resampler_initialize(4096)) return (-1); /* Set audio enable flag */ snd.enabled = 1; /* Reset audio */ audio_reset(); return (0); }
int audio_init(int samplerate, double framerate) { /* Shutdown first */ audio_shutdown(); /* Clear the sound data context */ memset(&snd, 0, sizeof (snd)); /* Initialize Blip Buffers */ snd.blips[0] = blip_new(samplerate / 10); if (!snd.blips[0]) { return -1; } /* Mega CD sound hardware */ if (system_hw == SYSTEM_MCD) { /* allocate blip buffers */ snd.blips[1] = blip_new(samplerate / 10); snd.blips[2] = blip_new(samplerate / 10); if (!snd.blips[1] || !snd.blips[2]) { audio_shutdown(); return -1; } } /* Initialize resampler internal rates */ audio_set_rate(samplerate, framerate); /* Set audio enable flag */ snd.enabled = 1; /* Reset audio */ audio_reset(); return (0); }
int OnQuickloadOk(const void *browser, const void *path) { int first_time = 0; if (!GAME_LOADED) first_time = 1; if (!load_rom((char*)path)) { pspUiAlert("Error loading cartridge"); return 0; } SET_AS_CURRENT_GAME((char*)path); pl_file_get_parent_directory((const char*)path, GamePath, sizeof(GamePath)); /* Reset selected state */ SaveStateGallery.Menu.selected = NULL; if (first_time) { pspUiFlashMessage("Initializing for first-time use\nPlease wait..."); audio_init(SOUND_FREQUENCY, 0); system_init(); //error_init(); system_reset(); } else{ system_init(); system_reset(); audio_reset(); } pl_rewind_reset(&Rewinder); ResumeEmulation = 1; return 1; }
static int audio_ioctl(struct inode *inode, struct file *file, uint cmd, ulong arg) { audio_state_t *state = file->private_data; audio_stream_t *os = state->output_stream; audio_stream_t *is = state->input_stream; long val; DPRINTK(__FILE__ " audio_ioctl 0x%08x\n", cmd); /* dispatch based on command */ switch (cmd) { case OSS_GETVERSION: return put_user(SOUND_VERSION, (int *)arg); case SNDCTL_DSP_GETBLKSIZE: if (file->f_mode & FMODE_WRITE) return put_user(os->fragsize, (int *)arg); else return put_user(is->fragsize, (int *)arg); case SNDCTL_DSP_GETCAPS: val = DSP_CAP_REALTIME|DSP_CAP_TRIGGER|DSP_CAP_MMAP; if (is && os) val |= DSP_CAP_DUPLEX; return put_user(val, (int *)arg); case SNDCTL_DSP_SETFRAGMENT: if (get_user(val, (long *) arg)) return -EFAULT; if (file->f_mode & FMODE_READ) { int ret = audio_set_fragments(is, val); if (ret < 0) return ret; ret = put_user(ret, (int *)arg); if (ret) return ret; } if (file->f_mode & FMODE_WRITE) { int ret = audio_set_fragments(os, val); if (ret < 0) return ret; ret = put_user(ret, (int *)arg); if (ret) return ret; } return 0; case SNDCTL_DSP_SYNC: return audio_sync(file); case SNDCTL_DSP_SETDUPLEX: return 0; case SNDCTL_DSP_POST: return 0; case SNDCTL_DSP_GETTRIGGER: val = 0; if (file->f_mode & FMODE_READ && is->active && !is->stopped) val |= PCM_ENABLE_INPUT; if (file->f_mode & FMODE_WRITE && os->active && !os->stopped) val |= PCM_ENABLE_OUTPUT; return put_user(val, (int *)arg); case SNDCTL_DSP_SETTRIGGER: if (get_user(val, (int *)arg)) return -EFAULT; if (file->f_mode & FMODE_READ) { if (val & PCM_ENABLE_INPUT) { unsigned long flags; if (!is->active) { if (!is->buffers && audio_setup_buf(is)) return -ENOMEM; audio_prime_rx(state); } local_irq_save(flags); is->stopped = 0; audio_process_dma(is); local_irq_restore(flags); } else { audio_stop_dma(is); } } if (file->f_mode & FMODE_WRITE) { if (val & PCM_ENABLE_OUTPUT) { unsigned long flags; if (!os->buffers && audio_setup_buf(os)) return -ENOMEM; local_irq_save(flags); if (os->mapped && !os->pending_frags) { os->pending_frags = os->nbfrags; sema_init(&os->sem, 0); os->active = 1; } os->stopped = 0; audio_process_dma(os); local_irq_restore(flags); } else { audio_stop_dma(os); } } return 0; case SNDCTL_DSP_GETOPTR: case SNDCTL_DSP_GETIPTR: { count_info inf = { 0, }; audio_stream_t *s = (cmd == SNDCTL_DSP_GETOPTR) ? os : is; int bytecount, offset; unsigned long flags; if ((s == is && !(file->f_mode & FMODE_READ)) || (s == os && !(file->f_mode & FMODE_WRITE))) return -EINVAL; if (s->active) { local_irq_save(flags); offset = audio_get_dma_pos(s); inf.ptr = s->dma_tail * s->fragsize + offset; bytecount = s->bytecount + offset; s->bytecount = -offset; inf.blocks = s->fragcount; s->fragcount = 0; local_irq_restore(flags); if (bytecount < 0) bytecount = 0; inf.bytes = bytecount; } return copy_to_user((void *)arg, &inf, sizeof(inf)); } case SNDCTL_DSP_GETOSPACE: case SNDCTL_DSP_GETISPACE: { audio_buf_info inf = { 0, }; audio_stream_t *s = (cmd == SNDCTL_DSP_GETOSPACE) ? os : is; if ((s == is && !(file->f_mode & FMODE_READ)) || (s == os && !(file->f_mode & FMODE_WRITE))) return -EINVAL; if (!s->buffers && audio_setup_buf(s)) return -ENOMEM; inf.bytes = atomic_read(&s->sem.count) * s->fragsize; /* inf.bytes -= s->buffers[s->usr_head].offset; */ inf.fragments = inf.bytes / s->fragsize; inf.fragsize = s->fragsize; inf.fragstotal = s->nbfrags; return copy_to_user((void *)arg, &inf, sizeof(inf)); } case SNDCTL_DSP_NONBLOCK: file->f_flags |= O_NONBLOCK; return 0; case SNDCTL_DSP_RESET: if (file->f_mode & FMODE_READ) { audio_reset(is); if (state->need_tx_for_rx) { unsigned long flags; local_irq_save(flags); os->spin_idle = 0; local_irq_restore(flags); } } if (file->f_mode & FMODE_WRITE) { audio_reset(os); } return 0; default: /* * Let the client of this module handle the * non generic ioctls */ return state->client_ioctl(inode, file, cmd, arg); } return 0; }
int omap_audio_attach(struct inode *inode, struct file *file, audio_state_t *state) { audio_stream_t *os = state->output_stream; audio_stream_t *is = state->input_stream; int err, need_tx_dma; DPRINTK("audio_open\n"); down(&state->sem); /* access control */ err = -ENODEV; if ((file->f_mode & FMODE_WRITE) && !os) goto out; if ((file->f_mode & FMODE_READ) && !is) goto out; err = -EBUSY; if ((file->f_mode & FMODE_WRITE) && state->wr_ref) goto out; if ((file->f_mode & FMODE_READ) && state->rd_ref) goto out; err = -EINVAL; if ((file->f_mode & FMODE_READ) && state->need_tx_for_rx && !os) goto out; /* request DMA channels */ need_tx_dma = ((file->f_mode & FMODE_WRITE) || ((file->f_mode & FMODE_READ) && state->need_tx_for_rx)); if (state->wr_ref || (state->rd_ref && state->need_tx_for_rx)) need_tx_dma = 0; if (need_tx_dma) { err = DMA_REQUEST(os, audio_dma_callback); if (err) goto out; } if (file->f_mode & FMODE_READ) { err = DMA_REQUEST(is, audio_dma_callback); if (err) { if (need_tx_dma) DMA_FREE(os); goto out; } } /* now complete initialisation */ if (!AUDIO_ACTIVE(state)) { if (state->hw_init) state->hw_init(state->data); #ifdef CONFIG_PM state->pm_dev = pm_register(PM_SYS_DEV, 0, audio_pm_callback); if (state->pm_dev) state->pm_dev->data = state; #endif } if ((file->f_mode & FMODE_WRITE)) { state->wr_ref = 1; audio_reset(os); os->fragsize = AUDIO_FRAGSIZE_DEFAULT; os->nbfrags = AUDIO_NBFRAGS_DEFAULT; os->mapped = 0; init_waitqueue_head(&os->wq); } if (file->f_mode & FMODE_READ) { state->rd_ref = 1; audio_reset(is); is->fragsize = AUDIO_FRAGSIZE_DEFAULT; is->nbfrags = AUDIO_NBFRAGS_DEFAULT; is->mapped = 0; init_waitqueue_head(&is->wq); } file->private_data = state; file->f_op->release = audio_release; file->f_op->write = audio_write; file->f_op->read = audio_read; file->f_op->mmap = audio_mmap; file->f_op->poll = audio_poll; file->f_op->ioctl = audio_ioctl; file->f_op->llseek = audio_llseek; err = 0; out: up(&state->sem); return err; }
int audio_open(snd_type snd, long *flags) { UINT devtoopen; WAVEOUTCAPS outspec; WAVEINCAPS inspec; MMRESULT er; HWAVE h; if (snd->u.audio.devicename[0] != '\000'){ if (audio_dev(snd, snd->u.audio.devicename, &devtoopen)){ return(!SND_SUCCESS); } } else { devtoopen = WAVE_MAPPER; //open what you find } er = win_wave_open(snd, devtoopen, &h); if (er != (MMRESULT) MMSYSERR_NOERROR) { if (er != WAVERR_BADFORMAT) { mm_error_handler(snd, er, snd_fail); return !SND_SUCCESS; } // The specified format isn't supported around here. // Let's try to use another one. if (devtoopen == WAVE_MAPPER) { UINT i, n, bestdev; format_node tempformat, bestformat = snd->format; long bestmatch = ((SND_HEAD_CHANNELS | SND_HEAD_MODE | SND_HEAD_BITS | SND_HEAD_SRATE) << 1) + 1; if (snd->write_flag == SND_READ) { n = waveInGetNumDevs(); for (i = 0; i < n; i++) { tempformat = snd->format; // non-zero means an error occurred: if (er = waveInGetDevCaps(i, &inspec, sizeof(WAVEINCAPS))) { char msg[64]; sprintf(msg, "Error at the %i device: %d\n", i, er); snd_fail(msg); } else { if (audio_formatmatch(&tempformat, inspec.dwFormats, flags) != SND_SUCCESS) { char msg[64]; sprintf(msg, "Problem with FormatMatching at device %i\n", i); } else if (numofbits(*flags) < numofbits(bestmatch)) { bestmatch = *flags; bestformat = tempformat; bestdev = i; } } } } else { n = waveOutGetNumDevs(); for (i = 0; i < n; i++) { tempformat = snd->format; // non-zero means an error occurred: if (er = waveOutGetDevCaps(i, &outspec, sizeof(WAVEOUTCAPS))) { char msg[64]; sprintf(msg, "Error at the %i device: %d\n", i, er); snd_fail(msg); } else { if (audio_formatmatch(&tempformat, outspec.dwFormats, flags) != SND_SUCCESS) { char msg[64]; sprintf(msg, "Problem with FormatMatching at device %i\n", i); } else if (numofbits(*flags) < numofbits(bestmatch)) { bestmatch = *flags; bestformat = tempformat; bestdev = i; } } } } if (bestmatch == ((long)-1)) { // We weren't able to pick up a device. Let's quit. return !SND_SUCCESS; } snd->format = bestformat; *flags = bestmatch; devtoopen = bestdev; // not devtoopen == WAVE_MAPPER, so open specified device, get format: } else if (snd->write_flag == SND_READ) { if (er = waveInGetDevCaps(devtoopen, &inspec, sizeof(WAVEINCAPS))) { mm_error_handler(snd, er, snd_fail); return !SND_SUCCESS; } if (audio_formatmatch(&snd->format, inspec.dwFormats, flags)) { snd_fail("Something went wrong with FormatMatching"); return !SND_SUCCESS; } } else { // snd->write_flag != SND_READ if (er = waveOutGetDevCaps(devtoopen, &outspec, sizeof(WAVEOUTCAPS))) { mm_error_handler(snd, er, snd_fail); return !SND_SUCCESS; } if (audio_formatmatch(&snd->format, outspec.dwFormats, flags)) { snd_fail("Something went wrong with FormatMatching"); return !SND_SUCCESS; } } if (er = win_wave_open(snd, devtoopen, &h)) { mm_error_handler(snd, er, snd_fail); return !SND_SUCCESS; } } if (snd->u.audio.protocol == SND_REALTIME && !rt_devices_open) { if (er = timeGetDevCaps(&tc, sizeof(TIMECAPS))) { mm_error_handler(snd, er, snd_fail); return !SND_SUCCESS; } wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax); if (er = timeBeginPeriod(wTimerRes)) { mm_error_handler(snd, er, snd_fail); return !SND_SUCCESS; } rt_devices_open++; } snd->u.audio.descriptor = audio_descr_build(snd); if (snd->u.audio.descriptor == NULL) { snd_fail("Unable to create Device-state descriptor"); return !SND_SUCCESS; } ((buffer_state *) snd->u.audio.descriptor)->u.h_in = (HWAVEIN) h; if (snd->write_flag == SND_READ) { audio_reset(snd); // audio buffers should be passed to the device here, // like in the Reset() function } return SND_SUCCESS; }
int s3c_audio_attach(struct inode *inode, struct file *file, audio_state_t *state) { audio_stream_t *os = state->output_stream; audio_stream_t *is = state->input_stream; int err, need_tx_dma=0; down(&state->sem); /* access control */ err = -ENODEV; if ((file->f_mode & FMODE_WRITE) && !os) goto out; if ((file->f_mode & FMODE_READ) && !is) goto out; err = -EBUSY; if ((file->f_mode & FMODE_WRITE) && state->wr_ref) goto out; if ((file->f_mode & FMODE_READ) && state->rd_ref) goto out; err = -EINVAL; if ((file->f_mode & FMODE_READ) && state->need_tx_for_rx && !os) goto out; if(file->f_mode & FMODE_READ) file->f_mode = FMODE_READ; /* request DMA channels */ if (file->f_mode & FMODE_WRITE) { if(s3c2410_dma_request(os->dma, &s3c_play_dma_client, NULL)) { printk(KERN_WARNING "unable to get DMA channel.\n" ); err = -EBUSY; goto out; } err = s3c_iis_dma_init(os,0); } if (file->f_mode & FMODE_READ) { if(s3c2410_dma_request(is->dma, &s3c_rec_dma_client, NULL)) { printk(KERN_WARNING "unable to get DMA channel.\n" ); err = -EBUSY; if (need_tx_dma) s3c2410_dma_free(is->dma,&s3c_play_dma_client); goto out; } err = s3c_iis_dma_init(is,1); } /* now complete initialisation */ if (!AUDIO_ACTIVE(state)) { if (state->hw_init) state->hw_init(state->data); } if ((file->f_mode & FMODE_WRITE)) { state->wr_ref = 1; audio_reset(os); os->fragsize = AUDIO_FRAGSIZE_DEFAULT; os->nbfrags = AUDIO_NBFRAGS_DEFAULT; os->mapped = 0; init_waitqueue_head(&os->wq); } if (file->f_mode & FMODE_READ) { state->rd_ref = 1; audio_reset(is); is->fragsize = AUDIO_FRAGSIZE_DEFAULT; is->nbfrags = AUDIO_NBFRAGS_DEFAULT; is->mapped = 0; init_waitqueue_head(&is->wq); } file->private_data = state; file->f_op = &s3c_f_ops; err = 0; out: up(&state->sem); return err; }
/* Reading thread of the buffer. */ static void *read_thread (void *arg) { struct out_buf *buf = (struct out_buf *)arg; int audio_dev_closed = 0; logit ("entering output buffer thread"); set_realtime_prio (); LOCK (buf->mutex); while (1) { int played = 0; char play_buf[AUDIO_MAX_PLAY_BYTES]; int play_buf_fill; int play_buf_pos = 0; if (buf->reset_dev && !audio_dev_closed) { audio_reset (); buf->reset_dev = 0; } if (buf->stop) fifo_buf_clear (&buf->buf); if (buf->free_callback) { /* unlock the mutex to make calls to out_buf functions * possible in the callback */ UNLOCK (buf->mutex); buf->free_callback (); LOCK (buf->mutex); } debug ("sending the signal"); pthread_cond_broadcast (&buf->ready_cond); if ((fifo_buf_get_fill(&buf->buf) == 0 || buf->pause || buf->stop) && !buf->exit) { if (buf->pause && !audio_dev_closed) { logit ("Closing the device due to pause"); audio_close (); audio_dev_closed = 1; } debug ("waiting for something in the buffer"); buf->read_thread_waiting = 1; pthread_cond_wait (&buf->play_cond, &buf->mutex); debug ("something appeared in the buffer"); } buf->read_thread_waiting = 0; if (audio_dev_closed && !buf->pause) { logit ("Opening the device again after pause"); if (!audio_open(NULL)) { logit ("Can't reopen the device! sleeping..."); sleep (1); /* there is no way to exit :( */ } else audio_dev_closed = 0; } if (fifo_buf_get_fill(&buf->buf) == 0) { if (buf->exit) { logit ("exit"); break; } logit ("buffer empty"); continue; } if (buf->pause) { logit ("paused"); continue; } if (buf->stop) { logit ("stopped"); continue; } if (!audio_dev_closed) { int audio_bpf; size_t play_buf_frames; audio_bpf = audio_get_bpf(); play_buf_frames = MIN(audio_get_bps() * AUDIO_MAX_PLAY, AUDIO_MAX_PLAY_BYTES) / audio_bpf; play_buf_fill = fifo_buf_get(&buf->buf, play_buf, play_buf_frames * audio_bpf); UNLOCK (buf->mutex); debug ("playing %d bytes", play_buf_fill); while (play_buf_pos < play_buf_fill) { played = audio_send_pcm ( play_buf + play_buf_pos, play_buf_fill - play_buf_pos); play_buf_pos += played; } /*logit ("done sending PCM");*/ /*write (fd, buf->buf + buf->pos, to_play);*/ LOCK (buf->mutex); /* Update time */ if (played && audio_get_bps()) buf->time += played / (float)audio_get_bps(); buf->hardware_buf_fill = audio_get_buf_fill(); } } UNLOCK (buf->mutex); logit ("exiting"); return NULL; }
int main(void) { //Variable Declarations initSolenoid(); /* initialize solenoid valve */ TIM_TIMERCFG_Type timerCfg; initTimeStruct(); RTC_TIME_Type* watertime = malloc(sizeof(RTC_TIME_Type)); uint8 fed = 0; uint8 watered = 0; watertime->HOUR = 5; watertime->MIN = 0; //Initialize timer0 for delays TIM_ConfigStructInit(TIM_TIMER_MODE, &timerCfg); /* initialize timer config struct */ TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &timerCfg); /* initialize timer0 */ //Initialize Real Time Clock RTC_Init(LPC_RTC); RTC_Cmd(LPC_RTC, ENABLE); RTC_ResetClockTickCounter(LPC_RTC); // Initialize Peripherals INIT_SDRAM(); /* initialize SDRAM */ servoInit(); /* initialize FSR servo motor for panning camera */ initStepper(); /* initialize stepper motor for dispensing food */ initFSR(); /* initialize force sensitive resistor circuit for food and water full signals */ initWiFi(AUTO_CONNECT); /* initialize WiFi module -- must be attached*/ audio_initialize(); audio_reset(); //audio_test(); audio_setupMP3(); int i = 0, retval; uint32 length; /* length variable for photo */ printf("Entering while loop\n\r"); //audio_storeVoice(); // Enter an infinite loop while(1) { if(STATE == DISPENSING_FOOD){ printf("Entering food dispense state\n\r"); /* Execute commands to dispense food */ //spinUntilFull(); spinStepper(300); reverseSpin(250); STATE = CONNECTED; } if(STATE == DISPENSING_WATER){ printf("Entering water dispense state\n\r"); /* Execute commands to dispense water */ fillWater(); STATE = CONNECTED; } if(STATE == CAPTURING){ printf("Entering camera taking state\n\r"); /* Initialize camera and set it up to take a picture */ if(cameraInit()) printf("Camera not initialized!\n\r"); retval = stopFrame(); length = getBufferLength(); printf("length: %i\n\r", length); /* Send length to Android application */ int temp_len = length; while(temp_len){ uart1PutChar(temp_len % 10); temp_len = temp_len / 10; } /* Send photo and finish set up */ getAndSendPhoto(length); resumeFrame(); STATE = CONNECTED; } if(STATE == TALKING1){ audio_playVoice(1); STATE = CONNECTED; } if(STATE == TALKING2){ audio_playVoice(2); STATE = CONNECTED; } if(STATE == TALKING3){ audio_playVoice(3); STATE = CONNECTED; } if(STATE == PAN_LEFT){ /* Execute commands to pan servo left */ panServo(LEFT); STATE = CONNECTED; } if(STATE == PAN_RIGHT){ /* Execute commands to pan servo right */ panServo(RIGHT); STATE = CONNECTED; } if(STATE == SCHEDULING){ /* Execute commands to schedule a feeding time */ STATE = CONNECTED; } /* Scheduling */ RTC_GetFullTime(LPC_RTC, time); //Fill water bowl at predetermined time if (time->HOUR == watertime->HOUR + 1 && watered == 1) watered = 0; if (watertime->HOUR == time->HOUR && watertime->MIN < time->MIN && watered == 0) { fillWater(); watered = 1; } //Feed dog on schedule if any cannot feed dog two consecutive hours for(i = 0; i < scheduled_feeds; i++) { if (time->HOUR == feedtime[i]->HOUR + 1 && fed == 1) fed = 0; if (feedtime[i]->HOUR == time->HOUR && feedtime[i]->MIN < time->MIN && fed == 0) { spinUntilFull(); fed = 1; } } } return 0; }
int audio_init(int samplerate, double framerate) { /* Number of M-cycles executed per second. */ /* All emulated chips are kept in sync by using a common oscillator (MCLOCK) */ /* */ /* The original console would run exactly 53693175 M-cycles per sec (53203424 for PAL), */ /* 3420 M-cycles per line and 262 (313 for PAL) lines per frame, which gives an exact */ /* framerate of 59.92 (49.70 for PAL) frames per second. */ /* */ /* Since audio samples are generated at the end of the frame, to prevent audio skipping */ /* or lag between emulated frames, number of samples rendered per frame must be set to */ /* output samplerate (number of samples played per second) divided by input framerate */ /* (number of frames emulated per seconds). */ /* */ /* On some systems, we may want to achieve 100% smooth video rendering by synchronizing */ /* frame emulation with VSYNC, which frequency is generally not exactly those values. */ /* In that case, input framerate (number of frames emulated per seconds) is the same as */ /* output framerate (number of frames rendered per seconds) by the host video hardware. */ /* */ /* When no framerate is specified, base clock is set to original master clock value. */ /* Otherwise, it is set to number of M-cycles emulated per line (fixed) multiplied by */ /* number of lines per frame (VDP mode specific) multiplied by input framerate. */ /* */ double mclk = framerate ? (MCYCLES_PER_LINE * (vdp_pal ? 313 : 262) * framerate) : system_clock; /* Shutdown first */ audio_shutdown(); /* Clear the sound data context */ memset(&snd, 0, sizeof (snd)); /* Initialize audio rates */ snd.sample_rate = samplerate; snd.frame_rate = framerate; /* Initialize Blip Buffers */ snd.blips[0][0] = blip_new(samplerate / 10); snd.blips[0][1] = blip_new(samplerate / 10); if (!snd.blips[0][0] || !snd.blips[0][1]) { audio_shutdown(); return -1; } /* For maximal accuracy, sound chips are running at their original rate using common */ /* master clock timebase so they remain perfectly synchronized together, while still */ /* being synchronized with 68K and Z80 CPUs as well. Mixed sound chip output is then */ /* resampled to desired rate at the end of each frame, using Blip Buffer. */ blip_set_rates(snd.blips[0][0], mclk, samplerate); blip_set_rates(snd.blips[0][1], mclk, samplerate); /* Initialize PSG core */ SN76489_Init(snd.blips[0][0], snd.blips[0][1], (system_hw < SYSTEM_MARKIII) ? SN_DISCRETE : SN_INTEGRATED); /* Mega CD sound hardware */ if (system_hw == SYSTEM_MCD) { /* allocate blip buffers */ snd.blips[1][0] = blip_new(samplerate / 10); snd.blips[1][1] = blip_new(samplerate / 10); snd.blips[2][0] = blip_new(samplerate / 10); snd.blips[2][1] = blip_new(samplerate / 10); if (!snd.blips[1][0] || !snd.blips[1][1] || !snd.blips[2][0] || !snd.blips[2][1]) { audio_shutdown(); return -1; } /* Initialize PCM core */ pcm_init(snd.blips[1][0], snd.blips[1][1]); /* Initialize CDD core */ cdd_init(snd.blips[2][0], snd.blips[2][1]); } /* Set audio enable flag */ snd.enabled = 1; /* Reset audio */ audio_reset(); return (0); }