/* Initialize the ADC for reading micbias values. Can sleep. */ static int sn95031_initialize_adc(struct snd_soc_codec *sn95031_codec) { int base_addr, chnl_addr; int value; int channel_index; /* Index of the first channel in which the stop bit is set */ channel_index = find_free_channel(sn95031_codec); if (channel_index < 0) { pr_err("No free ADC channels"); return channel_index; } base_addr = SN95031_ADC_CHNL_START_ADDR + channel_index; if (!(channel_index == 0 || channel_index == SN95031_ADC_LOOP_MAX)) { /* Reset stop bit for channels other than 0 and 12 */ value = snd_soc_read(sn95031_codec, base_addr); /* Set the stop bit to zero */ snd_soc_write(sn95031_codec, base_addr, value & 0xEF); /* Index of the first free channel */ base_addr++; channel_index++; } /* Since this is the last channel, set the stop bit to 1 by ORing the DIE_SENSOR_CODE with 0x10 */ snd_soc_write(sn95031_codec, base_addr, SN95031_AUDIO_DETECT_CODE | 0x10); chnl_addr = SN95031_ADC_DATA_START_ADDR + 2 * channel_index; pr_debug("mid_initialize : %x", chnl_addr); configure_adc(sn95031_codec, 1); return chnl_addr; }
void open_wav(char *wav) { TCHANINFO *inf; int i; struct t_wave *wavinf; FILE *snd; i=find_free_channel(); if (i==-1) return; last_channel=i; inf=chaninfo+i; snd=fopen(wav,"rb"); if (snd==NULL) { printf("Soubor %s neexistuje.\n",wav); return; } if (find_chunk(snd,WAV_FMT)==-1) { printf("Soubor %s ma poskozenou hlavicku\n",wav); fclose(snd); return; } wavinf=(struct t_wave *)malloc(get_chunk_size(snd)); if (wavinf==NULL) { puts("Nedostatek pamˆti."); return; } read_chunk(snd,wavinf); if (wavinf->wav_mode!=1) { printf("Tento program podporuje pouze WAVy typu 1 (%s)\n",wav); free(wavinf); fclose(snd); return; } inf->chans=wavinf->chans; inf->bit8=wavinf->freq*wavinf->chans==wavinf->bps; inf->repstart=-1; inf->id=-1; inf->left.volume=32768; inf->right.volume=32768; inf->left.vls=0; inf->right.vls=0; free(wavinf); if (find_chunk(snd,WAV_DATA)==0) { printf("Soubor %s je poskozen\n",wav); fclose(snd); return; } inf->size=get_chunk_size(snd); fseek(snd,4,SEEK_CUR); inf->snd=snd; }
static struct channel * open_channel(struct peer_connection *pc, uint8_t unordered, uint16_t pr_policy, uint32_t pr_value) { struct channel *channel; uint16_t o_stream; if ((pr_policy != SCTP_PR_SCTP_NONE) && (pr_policy != SCTP_PR_SCTP_TTL) && (pr_policy != SCTP_PR_SCTP_RTX)) { return (NULL); } if ((unordered != 0) && (unordered != 1)) { return (NULL); } if ((pr_policy == SCTP_PR_SCTP_NONE) && (pr_value != 0)) { return (NULL); } if ((channel = find_free_channel(pc)) == NULL) { return (NULL); } o_stream = find_free_o_stream(pc); channel->state = DATA_CHANNEL_CONNECTING; channel->unordered = unordered; channel->pr_policy = pr_policy; channel->pr_value = pr_value; channel->o_stream = o_stream; channel->flags = 0; if (o_stream == 0) { request_more_o_streams(pc); } else { if (send_open_request_message(pc->sock, o_stream, unordered, pr_policy, pr_value)) { pc->o_stream_channel[o_stream] = channel; } else { if (errno == EAGAIN) { pc->o_stream_channel[o_stream] = channel; channel->flags |= DATA_CHANNEL_FLAGS_SEND_REQ; } else { channel->state = DATA_CHANNEL_CLOSED; channel->unordered = 0; channel->pr_policy = 0; channel->pr_value = 0; channel->o_stream = 0; channel->flags = 0; channel = NULL; } } } return (channel); }
/** * mid_initialize_adc - initializing the ADC * @dev: our device structure * * Initialize the ADC for reading thermistor values. Can sleep. */ static int mid_initialize_adc(struct device *dev) { u8 data; u16 base_addr; int ret; /* * Ensure that adctherm is disabled before we * initialize the ADC */ ret = intel_msic_reg_read(INTEL_MSIC_ADC1CNTL3, &data); if (ret) return ret; data &= ~MSIC_ADCTHERM_MASK; ret = intel_msic_reg_write(INTEL_MSIC_ADC1CNTL3, data); if (ret) return ret; /* Index of the first channel in which the stop bit is set */ channel_index = find_free_channel(); if (channel_index < 0) { dev_err(dev, "No free ADC channels"); return channel_index; } base_addr = ADC_CHNL_START_ADDR + channel_index; if (!(channel_index == 0 || channel_index == ADC_LOOP_MAX)) { /* Reset stop bit for channels other than 0 and 12 */ ret = reset_stopbit(base_addr); if (ret) return ret; /* Index of the first free channel */ base_addr++; channel_index++; } ret = set_up_therm_channel(base_addr); if (ret) { dev_err(dev, "unable to enable ADC"); return ret; } dev_dbg(dev, "ADC initialization successful"); return ret; }
static int mid_initialize_adc(struct device *dev) { u8 data; u16 base_addr; int ret; ret = intel_msic_reg_read(INTEL_MSIC_ADC1CNTL3, &data); if (ret) return ret; data &= ~MSIC_ADCTHERM_MASK; ret = intel_msic_reg_write(INTEL_MSIC_ADC1CNTL3, data); if (ret) return ret; channel_index = find_free_channel(); if (channel_index < 0) { dev_err(dev, "No free ADC channels"); return channel_index; } base_addr = ADC_CHNL_START_ADDR + channel_index; if (!(channel_index == 0 || channel_index == ADC_LOOP_MAX)) { ret = reset_stopbit(base_addr); if (ret) return ret; base_addr++; channel_index++; } ret = set_up_therm_channel(base_addr); if (ret) { dev_err(dev, "unable to enable ADC"); return ret; } dev_dbg(dev, "ADC initialization successful"); return ret; }
static void handle_open_request_message(struct peer_connection *pc, struct rtcweb_datachannel_open_request *req, size_t length, uint16_t i_stream) { struct channel *channel; uint32_t pr_value; uint16_t pr_policy; uint16_t o_stream; uint8_t unordered; if ((channel = find_channel_by_i_stream(pc, i_stream))) { printf("handle_open_request_message: channel %d is in state %d instead of CLOSED.\n", channel->id, channel->state); /* XXX: some error handling */ return; } if ((channel = find_free_channel(pc)) == NULL) { /* XXX: some error handling */ return; } switch (req->channel_type) { case DATA_CHANNEL_RELIABLE: pr_policy = SCTP_PR_SCTP_NONE; break; /* XXX Doesn't make sense */ case DATA_CHANNEL_RELIABLE_STREAM: pr_policy = SCTP_PR_SCTP_NONE; break; /* XXX Doesn't make sense */ case DATA_CHANNEL_UNRELIABLE: pr_policy = SCTP_PR_SCTP_TTL; break; case DATA_CHANNEL_PARTIAL_RELIABLE_REXMIT: pr_policy = SCTP_PR_SCTP_RTX; break; case DATA_CHANNEL_PARTIAL_RELIABLE_TIMED: pr_policy = SCTP_PR_SCTP_TTL; break; default: pr_policy = SCTP_PR_SCTP_NONE; /* XXX error handling */ break; } pr_value = ntohs(req->reliability_params); if (ntohs(req->flags) & DATA_CHANNEL_FLAG_OUT_OF_ORDER_ALLOWED) { unordered = 1; } else { unordered = 0; } o_stream = find_free_o_stream(pc); channel->state = DATA_CHANNEL_CONNECTING; channel->unordered = unordered; channel->pr_policy = pr_policy; channel->pr_value = pr_value; channel->i_stream = i_stream; channel->o_stream = o_stream; channel->flags = 0; pc->i_stream_channel[i_stream] = channel; if (o_stream == 0) { request_more_o_streams(pc); } else { if (send_open_response_message(pc->sock, o_stream, i_stream)) { pc->o_stream_channel[o_stream] = channel; } else { if (errno == EAGAIN) { channel->flags |= DATA_CHANNEL_FLAGS_SEND_RSP; pc->o_stream_channel[o_stream] = channel; } else { /* XXX: Signal error to the other end. */ pc->i_stream_channel[i_stream] = NULL; channel->state = DATA_CHANNEL_CLOSED; channel->unordered = 0; channel->pr_policy = 0; channel->pr_value = 0; channel->i_stream = 0; channel->o_stream = 0; channel->flags = 0; } } } }
int main(int argc, char *argv[]) { FMOD_SYSTEM *system; FMOD_SOUND **fmod_sounds; FMOD_RESULT result; xmlDocPtr doc; xmlNodePtr node; int ret; ret = pthread_cond_init(&events.events_available, NULL); if (ret < 0) { fprintf(stderr, "Unable to initialize the events cond object\n"); } ret = pthread_mutex_init(&events.lock, NULL); if (ret < 0) { fprintf(stderr, "Unable to initialize the events lock object\n"); } init_sound_system(&system); init_xml_lib(); open_config_xml(&doc); node = doc->children; while (node) { if (xmlStrEqual(node->name, AUDIOTRIGGERS_ELT)) { break; } node = node->next; } if (!node) { fprintf(stderr, "Unable to find <audiotriggers> element at root of %s\n", CONFIG_XML); exit(1); } node = node->children; load_sounds_from_config(node); load_triggers_from_config(node); load_logfiles_from_config(node); close_config_xml(doc); fmod_sounds = malloc(sizeof(FMOD_SOUND *) * num_sounds); open_all_sounds(system, fmod_sounds); lfi = malloc(sizeof(struct log_file_info) * num_logfiles); open_all_logfiles(); match_triggers_with_sounds(); match_logfiles_with_triggers(); print_thankyou(); /* Main loop. */ pthread_mutex_lock(&events.lock); while (1) { int sound_id; while (events.cur == events.next) { debugmsg("event queue is empty\n"); pthread_cond_wait(&events.events_available, &events.lock); } events.cur = (events.cur + 1) % NUM_EVENTS; sound_id = events.entry[events.cur].sound_id; debugmsg("main loop received sound_id %d\n", sound_id); if (sound_id < num_sounds) { int free_channel; free_channel = find_free_channel(); if (free_channel == -1) { fprintf(stderr, "WARNING: No free channels! Dropping sound\n"); } else { result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, fmod_sounds[sound_id], 0, &channel[free_channel]); ERRCHECK(result); } } else { fprintf(stderr, "sound_id: %d exceeds the last sound_id: %d\n", sound_id, num_sounds - 1); exit(1); } } release_all_sounds(fmod_sounds); close_sound_system(system); return 0; }