int alsa_setup () { size_t chunk_bytes = 0; //<initialize alsa chunk_bytes = alsa_init (); //<Finally, allocate waveBuffer fprintf (stderr, "allocating %d samples\n", chunk_bytes); waveBuffer = (short *) malloc (chunk_bytes * sizeof (short)); if (waveBuffer == NULL) { fprintf (stderr, "not enough memory"); exit (EXIT_FAILURE); } //> //> return 0; }
void apply_prefs(gint alsa_change) { gint* vol_meter_clrs; scroll_step = g_key_file_get_integer_with_default(keyFile,"PNMixer","MouseScrollStep",1); if (g_key_file_get_boolean_with_default(keyFile,"PNMixer","EnableHotKeys",FALSE)) { gint mk,uk,dk,mm,um,dm,hstep; mk = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolMuteKey", -1); uk = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolUpKey", -1); dk = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolDownKey", -1); mm = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolMuteMods", 0); um = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolUpMods", 0); dm = g_key_file_get_integer_with_default(keyFile,"PNMixer", "VolDownMods", 0); hstep = g_key_file_get_integer_with_default(keyFile,"PNMixer", "HotkeyVolumeStep", 1); grab_keys(mk,uk,dk,mm,um,dm,hstep); } else grab_keys(-1,-1,-1,0,0,0,1); // will actually just ungrab everything set_notifications_booleans(); get_icon_theme(); if (alsa_change) alsa_init(); vol_meter_clrs = get_vol_meter_colors(); set_vol_meter_color(vol_meter_clrs[0],vol_meter_clrs[1],vol_meter_clrs[2]); g_free(vol_meter_clrs); update_status_icons(); update_vol_text(); }
/* initialize the sound card or connect to aRts server */ void audio_init(audio_dev_handle* handle, int rate, int latency, int try_arts) { #ifdef HAS_ARTS int artserr = 0; handle->arts_handle = NULL; handle->use_arts = 0; #endif handle->alsa_handle = NULL; handle->channels = 1; /* mono */ handle->format = SND_PCM_FORMAT_U8; handle->rate = rate; handle->latency = latency; /* in ms */ #ifdef HAS_ARTS if( try_arts ) { artserr = arts_init(); if( artserr < 0 ) { fprintf(stderr, "Error initializing aRts: %s\n", arts_error_text(artserr)); exit(-1); } handle->arts_handle = arts_play_stream( *rate, 8, handle->channels, "arts-whitenoise" ); arts_stream_set(handle->arts_handle, ARTS_P_BUFFER_TIME, *latency); handle->use_arts = 1; } else #endif { alsa_init(handle); } }
static int init(int argc, char **argv) { argc = argc<8000?44100:argc; if(audio == 0) { audio = open (audev, O_WRONLY); __UsbSoundCard = 1; alsa_init(NULL,NULL); if (audio < 0) { printf("open device failed,try again:\n"); sleep(4);//try again audio = open (audev, O_WRONLY); if (audio < 0) { die("Device opening failed\n"); return 1; } } if (ioctl(audio, I2S_DSIZE, 16) < 0) { die("I2S_DSIZE"); return 1; } if (ioctl(audio, I2S_FREQ, argc) < 0) { die("I2S_FREQ"); return 1; } if (ioctl(audio, I2S_MODE, 2) < 0) { die("I2S_MODE"); return 1; } if (ioctl(audio, I2S_MUTE, 0) < 0) { die("I2S_MUTE err"); return 1; } if (ioctl(audio, I2S_VOLUME, 80) < 0)//set max volume { die("set vol err\n"); return 1; } if(__UsbSoundCard) alsa_start(argc,2,16,100); return 0; } else return 1; }
/** * Reinitializes alsa and updates the various states. */ void do_alsa_reinit(void) { alsa_init(); update_status_icons(); update_vol_text(); on_volume_has_changed(); }
/** * Program entry point. Initializes gtk+, calls the widget creating * functions and starts the main loop. Also connects 'popup-menu', * 'activate' and 'button-release-event' to the tray_icon. * * @param argc count of arguments * @param argv string array of arguments * @return 0 for success, otherwise error code */ int main (int argc, char *argv[]) { GError *error = NULL; GOptionContext *context; #ifdef ENABLE_NLS bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif DEBUG_PRINT("[Debugging Mode Build]\n"); setlocale(LC_ALL, ""); context = g_option_context_new (_("- A mixer for the system tray.")); g_option_context_add_main_entries (context, args, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, &error); gtk_init (&argc, &argv); g_option_context_free(context); if (version) { printf(_("%s version: %s\n"),PACKAGE,VERSION); exit(0); } popup_window = NULL; status_icons[0] = status_icons[1] = status_icons[2] = status_icons[3] = NULL; add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); add_pixmap_directory ("./pixmaps"); ensure_prefs_dir(); load_prefs(); cards = NULL; // so we don't try and free on first run alsa_init(); init_libnotify(); create_popups(); add_filter(); tray_icon = create_tray_icon(); apply_prefs(0); g_signal_connect(G_OBJECT(tray_icon), "popup-menu",G_CALLBACK(popup_callback), popup_menu); g_signal_connect(G_OBJECT(tray_icon), "activate", G_CALLBACK(tray_icon_on_click), NULL); g_signal_connect(G_OBJECT(tray_icon), "button-release-event", G_CALLBACK(tray_icon_button), NULL); gtk_main (); uninit_libnotify(); alsa_close(); return 0; }
/* close the sound device and reopen with the requested rate */ void audio_set_rate(audio_dev_handle* handle, int rate) { handle->rate = rate; #ifdef HAS_ARTS if( handle->use_arts ) { arts_close_stream(handle->arts_handle); handle->arts_handle = arts_play_stream(rate, 8, handle->channels+1, "arts-whitenoise"); } else #endif { snd_pcm_close(handle->alsa_handle); alsa_init(handle); } }
/* configure the audio buffer sizes. The latency parameter is in millisec. */ void audio_set_latency(audio_dev_handle* handle, int latency) { handle->latency = latency; #ifdef HAS_ARTS if(handle->use_arts) { arts_close_stream(handle->arts_handle); handle->arts_handle = arts_play_stream(handle->rate, 8, handle->channels+1, "arts-whitenoise"); arts_stream_set(handle->arts_handle, ARTS_P_BUFFER_TIME, latency); } else #endif { snd_pcm_close(handle->alsa_handle); alsa_init(handle); } }
int main(int argc, char *argv[]) { int rc = -1, n, priority; const char *importer, *scanner, *geo; char *endptr; size_t nctl; double speed; struct timecode_def *timecode; bool protect, use_mlock, phono; struct controller ctl[2]; struct rt rt; struct library library; #if defined WITH_OSS || WITH_ALSA int rate; #endif #ifdef WITH_OSS int oss_buffers, oss_fragment; #endif #ifdef WITH_ALSA int alsa_buffer; #endif fprintf(stderr, "%s\n\n" NOTICE "\n\n", banner); if (thread_global_init() == -1) return -1; if (rig_init() == -1) return -1; rt_init(&rt); library_init(&library); ndeck = 0; geo = ""; nctl = 0; priority = DEFAULT_PRIORITY; importer = DEFAULT_IMPORTER; scanner = DEFAULT_SCANNER; timecode = NULL; speed = 1.0; protect = false; phono = false; use_mlock = false; #if defined WITH_OSS || WITH_ALSA rate = DEFAULT_RATE; #endif #ifdef WITH_ALSA alsa_buffer = DEFAULT_ALSA_BUFFER; #endif #ifdef WITH_OSS oss_fragment = DEFAULT_OSS_FRAGMENT; oss_buffers = DEFAULT_OSS_BUFFERS; #endif /* Skip over command name */ argv++; argc--; while (argc > 0) { if (!strcmp(argv[0], "-h")) { usage(stdout); return 0; #ifdef WITH_OSS } else if (!strcmp(argv[0], "-f")) { /* Set fragment size for subsequent devices */ if (argc < 2) { fprintf(stderr, "-f requires an integer argument.\n"); return -1; } oss_fragment = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-f requires an integer argument.\n"); return -1; } /* Fragment sizes greater than the default aren't useful * as they are dependent on DEVICE_FRAME */ if (oss_fragment < DEFAULT_OSS_FRAGMENT) { fprintf(stderr, "Fragment size must be %d or more; aborting.\n", DEFAULT_OSS_FRAGMENT); return -1; } argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-b")) { /* Set number of buffers for subsequent devices */ if (argc < 2) { fprintf(stderr, "-b requires an integer argument.\n"); return -1; } oss_buffers = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-b requires an integer argument.\n"); return -1; } argv += 2; argc -= 2; #endif #if defined WITH_OSS || WITH_ALSA } else if (!strcmp(argv[0], "-r")) { /* Set sample rate for subsequence devices */ if (argc < 2) { fprintf(stderr, "-r requires an integer argument.\n"); return -1; } rate = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-r requires an integer argument.\n"); return -1; } argv += 2; argc -= 2; #endif #ifdef WITH_ALSA } else if (!strcmp(argv[0], "-m")) { /* Set size of ALSA buffer for subsequence devices */ if (argc < 2) { fprintf(stderr, "-m requires an integer argument.\n"); return -1; } alsa_buffer = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-m requires an integer argument.\n"); return -1; } argv += 2; argc -= 2; #endif } else if (!strcmp(argv[0], "-d") || !strcmp(argv[0], "-a") || !strcmp(argv[0], "-j")) { int r; unsigned int sample_rate; struct deck *ld; struct device *device; struct timecoder *timecoder; /* Create a deck */ if (argc < 2) { fprintf(stderr, "-%c requires a device name as an argument.\n", argv[0][1]); return -1; } if (ndeck == ARRAY_SIZE(deck)) { fprintf(stderr, "Too many decks; aborting.\n"); return -1; } fprintf(stderr, "Initialising deck %zd (%s)...\n", ndeck, argv[1]); ld = &deck[ndeck]; device = &ld->device; timecoder = &ld->timecoder; ld->importer = importer; ld->protect = protect; /* Work out which device type we are using, and initialise * an appropriate device. */ switch(argv[0][1]) { #ifdef WITH_OSS case 'd': r = oss_init(device, argv[1], rate, oss_buffers, oss_fragment); break; #endif #ifdef WITH_ALSA case 'a': r = alsa_init(device, argv[1], rate, alsa_buffer); break; #endif #ifdef WITH_JACK case 'j': r = jack_init(device, argv[1]); break; #endif default: fprintf(stderr, "Device type is not supported by this " "distribution of xwax.\n"); return -1; } if (r == -1) return -1; sample_rate = device_sample_rate(device); /* Default timecode decoder where none is specified */ if (timecode == NULL) { timecode = timecoder_find_definition(DEFAULT_TIMECODE); assert(timecode != NULL); } timecoder_init(timecoder, timecode, speed, sample_rate, phono); /* Connect up the elements to make an operational deck */ r = deck_init(ld, &rt, ndeck); if (r == -1) return -1; /* Connect this deck to available controllers */ for (n = 0; n < nctl; n++) controller_add_deck(&ctl[n], &deck[ndeck]); /* Connect this deck to OSC server */ osc_add_deck(); ndeck++; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-t")) { /* Set the timecode definition to use */ if (argc < 2) { fprintf(stderr, "-t requires a name as an argument.\n"); return -1; } timecode = timecoder_find_definition(argv[1]); if (timecode == NULL) { fprintf(stderr, "Timecode '%s' is not known.\n", argv[1]); return -1; } argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-33")) { speed = 1.0; argv++; argc--; } else if (!strcmp(argv[0], "-45")) { speed = 1.35; argv++; argc--; } else if (!strcmp(argv[0], "-c")) { protect = true; argv++; argc--; } else if (!strcmp(argv[0], "-u")) { protect = false; argv++; argc--; } else if (!strcmp(argv[0], "--line")) { phono = false; argv++; argc--; } else if (!strcmp(argv[0], "--phono")) { phono = true; argv++; argc--; } else if (!strcmp(argv[0], "-k")) { use_mlock = true; track_use_mlock(); argv++; argc--; } else if (!strcmp(argv[0], "-q")) { if (argc < 2) { fprintf(stderr, "-q requires an integer argument.\n"); return -1; } priority = strtol(argv[1], &endptr, 10); if (*endptr != '\0') { fprintf(stderr, "-q requires an integer argument.\n"); return -1; } if (priority < 0) { fprintf(stderr, "Priority (%d) must be zero or positive.\n", priority); return -1; } argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-g")) { if (argc < 2) { fprintf(stderr, "-g requires an argument.\n"); return -1; } geo = argv[1]; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-i")) { /* Importer script for subsequent decks */ if (argc < 2) { fprintf(stderr, "-i requires an executable path " "as an argument.\n"); return -1; } importer = argv[1]; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-s")) { /* Scan script for subsequent libraries */ if (argc < 2) { fprintf(stderr, "-s requires an executable path " "as an argument.\n"); return -1; } scanner = argv[1]; argv += 2; argc -= 2; } else if (!strcmp(argv[0], "-l")) { /* Load in a music library */ if (argc < 2) { fprintf(stderr, "-%c requires a pathname as an argument.\n", argv[0][1]); return -1; } if (library_import(&library, scanner, argv[1]) == -1) return -1; argv += 2; argc -= 2; #ifdef WITH_ALSA } else if (!strcmp(argv[0], "--dicer")) { struct controller *c; if (nctl == sizeof ctl) { fprintf(stderr, "Too many controllers; aborting.\n"); return -1; } c = &ctl[nctl]; if (argc < 2) { fprintf(stderr, "Dicer requires an ALSA device name.\n"); return -1; } if (dicer_init(c, &rt, argv[1]) == -1) return -1; nctl++; argv += 2; argc -= 2; #endif } else { fprintf(stderr, "'%s' argument is unknown; try -h.\n", argv[0]); return -1; } } #ifdef WITH_ALSA alsa_clear_config_cache(); #endif if (ndeck == 0) { fprintf(stderr, "You need to give at least one audio device to use " "as a deck; try -h.\n"); return -1; } rc = EXIT_FAILURE; /* until clean exit */ if (osc_start((struct deck *)&deck, &library) == -1) return -1; osc_start_updater_thread(); /* Order is important: launch realtime thread first, then mlock. * Don't mlock the interface, use sparingly for audio threads */ if (rt_start(&rt, priority) == -1) return -1; if (use_mlock && mlockall(MCL_CURRENT) == -1) { perror("mlockall"); goto out_rt; } if (interface_start(&library, geo) == -1) goto out_rt; if (rig_main() == -1) goto out_interface; rc = EXIT_SUCCESS; fprintf(stderr, "Exiting cleanly...\n"); out_interface: interface_stop(); out_rt: rt_stop(&rt); for (n = 0; n < ndeck; n++) deck_clear(&deck[n]); for (n = 0; n < nctl; n++) controller_clear(&ctl[n]); timecoder_free_lookup(); library_clear(&library); rt_clear(&rt); rig_clear(); osc_stop(); thread_global_clear(); if (rc == EXIT_SUCCESS) fprintf(stderr, "Done.\n"); return rc; }
/** * Reinitializes alsa and updates the tray icon. */ void do_alsa_reinit (void) { alsa_init(); update_status_icons(); update_vol_text(); get_mute_state(TRUE); }
int Atcleci_Init(Tcl_Interp * interp) { int rc; size_t chunk_bytes = 0; void *eciHandle; void *eciLib; // < configure shared library symbols eciLib = dlopen(ECILIBRARYNAME, RTLD_LAZY); if (eciLib == NULL) { Tcl_AppendResult(interp, "Could not load ", ECILIBRARYNAME, "\nPlease install the IBM ViaVoice Outloud RTK", NULL); return TCL_ERROR; } _eciVersion = (void (*)(char *)) (unsigned long) dlsym(eciLib, "eciVersion"); _eciGetAvailableLanguages = (int (*)(enum ECILanguageDialect *, int *)) (unsigned long) dlsym(eciLib, "eciGetAvailableLanguages"); _eciNewEx = (void *(*)(enum ECILanguageDialect)) (unsigned long) dlsym(eciLib, "eciNewEx"); _eciDelete = (void (*)(void *)) (unsigned long) dlsym(eciLib, "eciDelete"); _eciReset = (int (*)(void *)) (unsigned long) dlsym(eciLib, "eciReset"); _eciStop = (int (*)(void *)) (unsigned long) dlsym(eciLib, "eciStop"); _eciClearInput = (int (*)(void *)) (unsigned long) dlsym(eciLib, "eciClearInput"); _eciPause = (int (*)(void *, int)) (unsigned long) dlsym(eciLib, "eciPause"); _eciSynthesize = (int (*)(void *)) (unsigned long) dlsym(eciLib, "eciSynthesize"); _eciSynchronize = (int (*)(void *)) (unsigned long) dlsym(eciLib, "eciSynchronize"); _eciSpeaking = (int (*)(void *)) (unsigned long) dlsym(eciLib, "eciSpeaking"); _eciInsertIndex = (int (*)(void *, int)) (unsigned long) dlsym(eciLib, "eciInsertIndex"); _eciAddText = (int (*)(void *, char *)) (unsigned long) dlsym(eciLib, "eciAddText"); _eciSetParam = (int (*)(void *, int, int)) (unsigned long) dlsym(eciLib, "eciSetParam"); _eciGetVoiceParam = (int (*)(void *, int, int)) (unsigned long) dlsym(eciLib, "eciGetVoiceParam"); _eciSetVoiceParam = (int (*)(void *, int, int, int)) (unsigned long) dlsym(eciLib, "eciSetVoiceParam"); _eciRegisterCallback = (void (*)(void *, int (*)(void *, int, long, void *), void *)) (unsigned long) dlsym(eciLib, "eciRegisterCallback"); _eciSetOutputBuffer = (int (*)(void *, int, short *)) (unsigned long) dlsym(eciLib, "eciSetOutputBuffer"); _eciSetOutputDevice = (int (*)(void *, int)) (unsigned long) dlsym(eciLib, "eciSetOutputDevice"); // > // < check for needed symbols int okay = 1; if (!_eciNewEx) { okay = 0; Tcl_AppendResult(interp, "eciNewEx undef\n", NULL); } if (!_eciDelete) { okay = 0; Tcl_AppendResult(interp, "eciDelete undef\n", NULL); } if (!_eciReset) { okay = 0; Tcl_AppendResult(interp, "eciReset undef\n", NULL); } if (!_eciStop) { okay = 0; Tcl_AppendResult(interp, "eciStop undef\n", NULL); } if (!_eciClearInput) { okay = 0; Tcl_AppendResult(interp, "eciClearInput undef\n", NULL); } if (!_eciPause) { okay = 0; Tcl_AppendResult(interp, "eciPause undef\n", NULL); } if (!_eciSynthesize) { okay = 0; Tcl_AppendResult(interp, "eciSynthesize undef\n", NULL); } if (!_eciSpeaking) { okay = 0; Tcl_AppendResult(interp, "eciSpeaking undef\n", NULL); } if (!_eciInsertIndex) { okay = 0; Tcl_AppendResult(interp, "eciInsertIndex undef\n", NULL); } if (!_eciAddText) { okay = 0; Tcl_AppendResult(interp, "eciAddText undef\n", NULL); } if (!_eciSetParam) { okay = 0; Tcl_AppendResult(interp, "eciSetParam undef\n", NULL); } if (!_eciSetParam) { okay = 0; Tcl_AppendResult(interp, "eciSetParam undef\n", NULL); } if (!_eciGetVoiceParam) { okay = 0; Tcl_AppendResult(interp, "eciGetVoiceParam undef\n", NULL); } if (!_eciSetVoiceParam) { okay = 0; Tcl_AppendResult(interp, "eciSetVoiceParam undef\n", NULL); } if (!_eciRegisterCallback) { okay = 0; Tcl_AppendResult(interp, "eciRegisterCallback undef\n", NULL); } if (!_eciSetOutputBuffer) { okay = 0; Tcl_AppendResult(interp, "eciSetOutputBuffer undef\n", NULL); } if (!_eciSetOutputDevice) { okay = 0; Tcl_AppendResult(interp, "eciSetOutputDevice undef\n", NULL); } if (!_eciGetAvailableLanguages) { okay = 0; Tcl_AppendResult(interp, "_eciGetAvailableLanguages undef\n", NULL); } if (!okay) { Tcl_AppendResult(interp, "Missing symbols from ", ECILIBRARYNAME, NULL); return TCL_ERROR; } // > // <setup package, create tts handle if (Tcl_PkgProvide(interp, PACKAGENAME, PACKAGEVERSION) != TCL_OK) { Tcl_AppendResult(interp, "Error loading ", PACKAGENAME, NULL); return TCL_ERROR; } static enum ECILanguageDialect aLanguages[LANG_INFO_MAX]; int nLanguages = LANG_INFO_MAX; _eciGetAvailableLanguages(aLanguages, &nLanguages); enum ECILanguageDialect aDefaultLanguage = initLanguage(interp, aLanguages, nLanguages); if (aDefaultLanguage == NODEFINEDCODESET) { Tcl_AppendResult(interp, "No language found", PACKAGENAME, NULL); return TCL_ERROR; } eciHandle = _eciNewEx(aDefaultLanguage); if (eciHandle == 0) { Tcl_AppendResult(interp, "Could not open text-to-speech engine", NULL); return TCL_ERROR; } // > // <initialize alsa chunk_bytes = alsa_init(); // <Finally, allocate waveBuffer fprintf(stderr, "allocating %d samples\n", chunk_bytes); waveBuffer = (short *) malloc(chunk_bytes * sizeof(short)); if (waveBuffer == NULL) { fprintf(stderr, "not enough memory"); exit(EXIT_FAILURE); } // > // > // <initialize TTS if ((_eciSetParam(eciHandle, eciInputType, 1) == -1) || (_eciSetParam(eciHandle, eciSynthMode, 1) == -1) || (_eciSetParam(eciHandle, eciSampleRate, 1) == -1)) { Tcl_AppendResult(interp, "Could not initialized tts", NULL); _eciDelete(eciHandle); return TCL_ERROR; } _eciRegisterCallback(eciHandle, eciCallback, interp); // > // <set output to buffer rc = _eciSynchronize(eciHandle); if (!rc) { Tcl_AppendResult(interp, "Error resetting TTS engine.\n", NULL); return TCL_ERROR; } rc = _eciSetOutputBuffer(eciHandle, chunk_bytes, waveBuffer); if (!rc) { Tcl_AppendResult(interp, "Error setting output buffer.\n", NULL); return TCL_ERROR; } fprintf(stderr, "output buffered to waveBuffer with size %d\n", chunk_bytes); // > // <register tcl commands Tcl_CreateObjCommand(interp, "setRate", SetRate, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "getRate", GetRate, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "ttsVersion", getTTSVersion, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "alsaState", showAlsaState, (ClientData) NULL, TclEciFree); Tcl_CreateObjCommand(interp, "say", Say, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "synth", Say, (ClientData) eciHandle, NULL); Tcl_CreateObjCommand(interp, "synchronize", Synchronize, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "stop", Stop, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "speakingP", SpeakingP, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "pause", Pause, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "resume", Resume, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "setOutput", setOutput, (ClientData) eciHandle, TclEciFree); Tcl_CreateObjCommand(interp, "setLanguage", SetLanguage, (ClientData) eciHandle, TclEciFree); // > // <set up index processing rc = Tcl_Eval(interp, "proc index x {global tts; \ set tts(last_index) $x}");
static inline __init int alsa_init(void) { struct snd_kcontrol_new ctl_onoff = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Switch", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .info = playback_switch_info, .get = playback_switch_get, .put = playback_switch_put }; struct snd_kcontrol_new ctl_volume = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Master Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .info = playback_pot_info, .get = playback_pot_get, .put = playback_pot_put, .private_value = 1, }; struct snd_kcontrol_new ctl_tone = { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "Bass Playback Volume", .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, .info = playback_pot_info, .get = playback_pot_get, .put = playback_pot_put, .private_value = 0, }; int ret; ret = snd_card_create(-1, "Itrigue", THIS_MODULE, 0, &card); if( ret ) return ret; strcpy( card->driver, "I-Trigue" ); strcpy( card->shortname, "I-Trigue 3300" ); sprintf( card->longname, "%s at spi %d.%d (@ %d Hz), gpio %d", card->shortname, pot_spi_bus, pot_spi_cs, speed_hz, onoff_gpio ); /* ALSA controls */ ret = snd_ctl_add( card, snd_ctl_new1( &ctl_onoff, NULL ) ); if( ret ) goto bailout; ret = snd_ctl_add( card, snd_ctl_new1( &ctl_volume, NULL ) ); if( ret ) goto bailout; ret = snd_ctl_add( card, snd_ctl_new1( &ctl_tone, NULL ) ); if( ret ) goto bailout; ret = snd_card_register( card ); if( ret ) goto bailout; return ret; bailout: snd_card_free( card ); return ret; } static inline void alsa_exit(void) { snd_card_free( card ); } /* SETUP MODULE */ static int __init itrigue_init(void) { int ret; ret = gpio_init(); if( ret ) return ret; ret = spi_init(); if( ret ) { gpio_exit(); return ret; } ret = alsa_init(); if( ret ) { spi_exit(); gpio_exit(); return ret; } return ret; } static void __exit itrigue_exit(void) { alsa_exit(); spi_exit(); printk(KERN_INFO "I-Trigue 3300 off.\n"); gpio_exit(); }
void open_local_sound(char* adevice) { alsa_init(adevice); alsa_open(48000, 2, 8192); }
int main(int argc, char *argv[]){ int note = -1; /* MIDI note we are currently playing. */ int note_update = 1; /* If 1, the note has changed; * re-send the output voltage. */ int pitchbend = 8192; /* Current pitchbend value. 8192 = no bend. */ snd_seq_t *seqhandle; /* ALSA Sequencer handle */ snd_seq_event_t *ev; /* Sequencer event for handling MIDI messages. */ int npfd; /* Number of pollfds */ struct pollfd *pfd; /* Storage for array of struct pollfd, used for * polling for MIDI messages. */ if(argc != 2){ fputs(usage, stderr); return -1; } if(serialcv_init(argv[1], VREF)){ fputs("monotron: could not open serial port\n", stderr); return -2; } if(alsa_init(&seqhandle)){ fputs("monotron: coudle not open ALSA sequencer\n", stderr); serialcv_shutdown(); return -3; } npfd = snd_seq_poll_descriptors_count(seqhandle, POLLIN); pfd = malloc(npfd * sizeof(struct pollfd)); if(NULL == pfd){ fputs("monotron: malloc failure\n", stderr); serialcv_shutdown(); alsa_shutdown(seqhandle); } snd_seq_poll_descriptors(seqhandle, pfd, npfd, POLLIN); signal(SIGINT, terminate_loop); signal(SIGTERM, terminate_loop); while(!gotsignal){ if(note_update){ if(note >= 0){ serialcv_voltage(note_voltage(note) + pitchbend_voltage(pitchbend)); } else { serialcv_voltage(note_voltage(-1)); } note_update = 0; } if(poll(pfd, npfd, 1000) > 0){ /* MIDI Message received */ do{ snd_seq_event_input(seqhandle, &ev); if(MIDI_CH == ev->data.control.channel){ switch(ev->type){ case SND_SEQ_EVENT_PITCHBEND: pitchbend = ev->data.control.value; note_update = 1; break; case SND_SEQ_EVENT_NOTEON: if(0 == ev->data.note.velocity){ if(ev->data.note.note == note){ note = -1; note_update = 1; } } else { note = ev->data.note.note; /* Briefly output the idle voltage to * re-trigger the synth's EG */ serialcv_voltage(IDLE_VOLTS); note_update = 1; } break; case SND_SEQ_EVENT_NOTEOFF: if(ev->data.note.note == note){ note = -1; note_update = 1; } break; } } snd_seq_free_event(ev); }while(snd_seq_event_input_pending(seqhandle, 0)); } } serialcv_shutdown(); alsa_shutdown(seqhandle); free(pfd); return 0; }