void SoundEditor::draw () { long first, last, selectedSamples; Graphics_Viewport viewport; int showAnalysis = _spectrogram.show || _pitch.show || _intensity.show || _formant.show; Melder_assert (_data != NULL); Melder_assert (_sound.data != NULL || _longSound.data != NULL); /* * We check beforehand whether the window fits the LongSound buffer. */ if (_longSound.data && _endWindow - _startWindow > _longSound.data -> bufferLength) { Graphics_setColour (_graphics, Graphics_WHITE); Graphics_setWindow (_graphics, 0, 1, 0, 1); Graphics_fillRectangle (_graphics, 0, 1, 0, 1); Graphics_setColour (_graphics, Graphics_BLACK); Graphics_setTextAlignment (_graphics, Graphics_CENTRE, Graphics_BOTTOM); Graphics_text3 (_graphics, 0.5, 0.5, L"(window longer than ", Melder_float (Melder_single (_longSound.data -> bufferLength)), L" seconds)"); Graphics_setTextAlignment (_graphics, Graphics_CENTRE, Graphics_TOP); Graphics_text1 (_graphics, 0.5, 0.5, L"(zoom in to see the samples)"); return; } /* Draw sound. */ if (showAnalysis) viewport = Graphics_insetViewport (_graphics, 0, 1, 0.5, 1); Graphics_setColour (_graphics, Graphics_WHITE); Graphics_setWindow (_graphics, 0, 1, 0, 1); Graphics_fillRectangle (_graphics, 0, 1, 0, 1); draw_sound (_sound.minimum, _sound.maximum); Graphics_flushWs (_graphics); if (showAnalysis) Graphics_resetViewport (_graphics, viewport); /* Draw analyses. */ if (showAnalysis) { /* Draw spectrogram, pitch, formants. */ viewport = Graphics_insetViewport (_graphics, 0, 1, 0, 0.5); draw_analysis (); Graphics_flushWs (_graphics); Graphics_resetViewport (_graphics, viewport); } /* Draw pulses. */ if (_pulses.show) { if (showAnalysis) viewport = Graphics_insetViewport (_graphics, 0, 1, 0.5, 1); draw_analysis_pulses (); draw_sound (_sound.minimum, _sound.maximum); /* Second time, partially across the pulses. */ Graphics_flushWs (_graphics); if (showAnalysis) Graphics_resetViewport (_graphics, viewport); } /* Update buttons. */ selectedSamples = Sampled_getWindowSamples (_data, _startSelection, _endSelection, & first, & last); updateMenuItems_file (); if (_sound.data) { GuiObject_setSensitive (_cutButton, selectedSamples != 0 && selectedSamples < _sound.data -> nx); GuiObject_setSensitive (_copyButton, selectedSamples != 0); GuiObject_setSensitive (_zeroButton, selectedSamples != 0); GuiObject_setSensitive (_reverseButton, selectedSamples != 0); } }
void * hax_sdl_main(void *configuration) { hax_thread_config_t * hax_configs = (hax_thread_config_t *) configuration; hax_general_settings_t * hax_user_settings = &hax_configs->user_settings; hax_sdl_data * hax_sound_data = (hax_sdl_data *) hax_configs->data_zone; printf("[SDL] Thread Start!\n"); FPSmanager hax_fps; float displ = 0; SDL_initFramerate(&hax_fps); SDL_setFramerate(&hax_fps, 60); // SDL video initialisation if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); pthread_exit((void *) 1); } atexit(SDL_Quit); SDL_Surface* screen = SDL_SetVideoMode(hax_user_settings->window_w, hax_user_settings->window_h, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); if ( !screen ) { printf("Unable to set %i x %i video: %s\n", hax_user_settings->window_w, hax_user_settings->window_h, SDL_GetError()); pthread_exit((void *) 1); } printf("[SDL] Waiting to start...\n"); fflush(stdout); std::cout.flush(); hax_configs->timer->start(); printf("[SDL] Firing Loop!\n"); fflush(stdout); std::cout.flush(); while (*hax_user_settings->message) { hax_configs->timer->wait_next_activation(); hax_configs->timer->stat_execution_start(); // We catch an SDL signal SDL_Event event; while (SDL_PollEvent(&event)) { // If there was any signal switch (event.type) { // We exit if the window is closed case SDL_QUIT: *hax_user_settings->message = false; break; // We also check for keypresses case SDL_KEYDOWN: { // Then we exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) *hax_user_settings->message = false; break; } } } // end of message processing // At first we clear the screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); vlineColor(screen, screen->w / 2, 0, screen->h, 0xffffffff); printf("[SDL] Requiring Locks!\n"); fflush(stdout); std::cout.flush(); // Here we lock the data and then plot amplitude and spectrums hax_sound_data->lock_data(); printf("[SDL] Plotting Sound Data!\n"); fflush(stdout); std::cout.flush(); draw_sound(screen, hax_sound_data->get_frames(), hax_sound_data->get_left_sound_channel(), hax_sound_data->get_right_sound_channel(), (screen->h)/7, (screen->h)/7, 0xff00ffff); draw_real_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_right_spectrum(), (screen->h*7)/14, ((screen->h)/14), (char *)"Right", 0x00ffffff ); draw_imaginary_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_right_spectrum(), (screen->h*9)/14, ((screen->h)/14), (char *)"Right", 0x00ffffff ); draw_real_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_left_spectrum(), (screen->h*11)/14, ((screen->h)/14), (char *)"Left", 0x00ffffff); draw_imaginary_spectrum(screen, hax_sound_data->get_frames(), hax_sound_data->get_left_spectrum(), (screen->h*13)/14, ((screen->h)/14), (char *)"Left", 0x00ffffff ); printf("[SDL] Releasing Locks!\n"); fflush(stdout); std::cout.flush(); hax_sound_data->unlock_data(); // Finally, we update the screen SDL_Flip(screen); displ ++; hax_configs->timer->stat_update(); } printf("Exited cleanly\n"); // Printing Thread Statistics hax_configs->timer->stats_print(); pthread_exit((void *) 0); }