Exemplo n.º 1
0
void nrf_drv_pwm_complex_playback(nrf_drv_pwm_t const * const p_instance,
                                  nrf_pwm_sequence_t const * p_sequence_0,
                                  nrf_pwm_sequence_t const * p_sequence_1,
                                  uint16_t                   playback_count,
                                  uint32_t                   flags)
{
    pwm_control_block_t * p_cb  = &m_cb[p_instance->drv_inst_idx];
    ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
    ASSERT(playback_count > 0);
    ASSERT(nrf_drv_is_in_RAM(p_sequence_0->values.p_raw));
    ASSERT(nrf_drv_is_in_RAM(p_sequence_1->values.p_raw));

    nrf_pwm_sequence_set(p_instance->p_registers, 0, p_sequence_0);
    nrf_pwm_sequence_set(p_instance->p_registers, 1, p_sequence_1);
    nrf_pwm_loop_set(p_instance->p_registers, playback_count);

    uint32_t shorts_mask;
    if (flags & NRF_DRV_PWM_FLAG_STOP)
    {
        shorts_mask = NRF_PWM_SHORT_LOOPSDONE_STOP_MASK;
    }
    else if (flags & NRF_DRV_PWM_FLAG_LOOP)
    {
        shorts_mask = NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK;
    }
    else
    {
        shorts_mask = 0;
    }
    nrf_pwm_shorts_set(p_instance->p_registers, shorts_mask);

    start_playback(p_instance, p_cb, flags, NRF_PWM_TASK_SEQSTART0);
}
Exemplo n.º 2
0
int
rzx_start_playback_from_buffer( const unsigned char *buffer, size_t length )
{
  int error;
  libspectrum_snap* snap;

  if( rzx_recording ) return 0;

  rzx = libspectrum_rzx_alloc();

  error = libspectrum_rzx_read( rzx, buffer, length );
  if( error ) return error;

  snap = rzx_get_initial_snapshot();
  if( !snap ) {
    error = utils_open_snap();
    if( error ) {
      libspectrum_rzx_free( rzx );
      return error;
    }
  }

  error = start_playback( rzx );
  if( error ) {
    libspectrum_rzx_free( rzx );
    return error;
  }

  return 0;
}
Exemplo n.º 3
0
static gboolean advance_playback(gpointer data)
{
	struct con_win *cwin = data;
	GtkTreePath *path, *last_path;
	struct musicobject *mobj = NULL;
	GThread *thread;

	if (cwin->cstate->advance_track) {

		CDEBUG(DBG_INFO, "Advancing to next track");

		if (cwin->cstate->c_thread)
			g_thread_join(cwin->cstate->c_thread);

		gdk_threads_enter();
		unset_current_song_info(cwin);
		unset_track_progress_bar(cwin);
		gdk_threads_leave();

		cwin->cstate->c_thread = NULL;

		if (cwin->cstate->curr_mobj_clear)
			delete_musicobject(cwin->cstate->curr_mobj);

		/* Get the next track to be played */

		cwin->cstate->state = ST_STOPPED;
		play_button_toggle_state(cwin);

		last_path = current_playlist_get_actual(cwin);
		if (last_path) {
			update_pixbuf_state_on_path(last_path, cwin);
			gtk_tree_path_free(last_path);
		}

		path = current_playlist_get_next(cwin);
		if (!path) {
			#ifdef HAVE_LIBGLYR
			update_related_state(cwin);
			#endif
			return FALSE;
		}

		/* Start playing new track */

		mobj = current_playlist_mobj_at_path(path, cwin);

		thread = start_playback(mobj, cwin);
		if (!thread)
			g_critical("Unable to create playback thread");
		else
			update_current_state(thread, path, PLAYLIST_NEXT, cwin);

		gtk_tree_path_free(path);
	}

	return FALSE;
}
Exemplo n.º 4
0
/************************************************************************
*                                                                       *
*  Notifier proceedure for start/stop buttons
*
*/
void
Win_movie::start_stop(Panel_item, int value, Event *)
{
    switch (value){
      case 0:
	play_direction = BACKWARD;
	start_playback();
	break;

      case 1:
	stop_playback();
	break;

      case 2:
	play_direction = FORWARD;
	start_playback();
	break;
    }
}
Exemplo n.º 5
0
void start_game_check_replay()
{
    write_log_debug("Checking replay status");

    if (play.recording) {
        start_recording();
    }
    else if (play.playback) {
        start_playback();
    }
}
Exemplo n.º 6
0
void RecordMonitor::reconfig()
{
	stop_playback();
	VideoOutConfig config = *device->out_config; 
	device->close_all();
	device->open_output(&config, 
		record->default_asset->frame_rate, 
		record->default_asset->width, 
		record->default_asset->height,
		window->canvas, 0);
	start_playback();
	redraw();
}
Exemplo n.º 7
0
static void resume_device(ALCdevice *pDevice) {
    SLresult result;
    if (pDevice) {
        opesles_data_t *devState = (opesles_data_t *) pDevice->ExtraData;
        if (devState->bqPlayerPlay) {
            result = (*devState->bqPlayerPlay)->SetPlayState(devState->bqPlayerPlay, SL_PLAYSTATE_PLAYING);
            assert(SL_RESULT_SUCCESS == result);
            // Pump some blank data into the buffer to stimulate the callback
            result = (*devState->bqPlayerBufferQueue)->Enqueue(devState->bqPlayerBufferQueue, "\0", 1);
            assert(SL_RESULT_SUCCESS == result);
        }
        start_playback(pDevice);
     }
 }
void print_string(const char *string, int num_lines, int freq_min, int freq_max, int col_time_ms)
{
    Context context;
    Pa_Initialize();
    context_init(&context, num_lines, freq_min, freq_max, col_time_ms);
    start_playback(&context);
    int num_cols = 0;
    const char *message = prepare_message(string, &num_cols);
    for (int col = 0; col < num_cols; col++) {
        const char *col_start = message + col*ROWS_PER_LETTER;
        print_text_column(&context, col_start, ROWS_PER_LETTER);
    }
    free((void*)message);
    stop_playback(&context);
    Pa_Terminate();
    context_dealloc(&context);
}
uint32_t nrfx_pwm_complex_playback(nrfx_pwm_t const * const p_instance,
                                   nrf_pwm_sequence_t const * p_sequence_0,
                                   nrf_pwm_sequence_t const * p_sequence_1,
                                   uint16_t                   playback_count,
                                   uint32_t                   flags)
{
    pwm_control_block_t * p_cb  = &m_cb[p_instance->drv_inst_idx];
    NRFX_ASSERT(p_cb->state != NRFX_DRV_STATE_UNINITIALIZED);
    NRFX_ASSERT(playback_count > 0);
    NRFX_ASSERT(nrfx_is_in_ram(p_sequence_0->values.p_raw));
    NRFX_ASSERT(nrfx_is_in_ram(p_sequence_1->values.p_raw));

    nrf_pwm_sequence_set(p_instance->p_registers, 0, p_sequence_0);
    nrf_pwm_sequence_set(p_instance->p_registers, 1, p_sequence_1);
    nrf_pwm_loop_set(p_instance->p_registers, playback_count);

    uint32_t shorts_mask;
    if (flags & NRFX_PWM_FLAG_STOP)
    {
        shorts_mask = NRF_PWM_SHORT_LOOPSDONE_STOP_MASK;
    }
    else if (flags & NRFX_PWM_FLAG_LOOP)
    {
        shorts_mask = NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK;
    }
    else
    {
        shorts_mask = 0;
    }
    nrf_pwm_shorts_set(p_instance->p_registers, shorts_mask);

    NRFX_LOG_INFO("Function: %s, sequence 0 length: %d.",
                  __func__,
                  p_sequence_0->length);
    NRFX_LOG_INFO("Function: %s, sequence 1 length: %d.",
                  __func__,
                  p_sequence_1->length);
    NRFX_LOG_DEBUG("Sequence 0 data:");
    NRFX_LOG_HEXDUMP_DEBUG(p_sequence_0->values.p_raw,
                           p_sequence_0->length * sizeof(uint16_t));
    NRFX_LOG_DEBUG("Sequence 1 data:");
    NRFX_LOG_HEXDUMP_DEBUG(p_sequence_1->values.p_raw,
                           p_sequence_1->length * sizeof(uint16_t));
    return start_playback(p_instance, p_cb, flags, NRF_PWM_TASK_SEQSTART0);
}
Exemplo n.º 10
0
Music::Music() {
    Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096);
	Mix_VolumeMusic(MIX_MAX_VOLUME/4);
    
    cout << "Loading music" << endl;
    sceneintensity = 0;
    shouldbeplaying = false;
    
    ambient_tracks.resize(10);
    track_numbers.resize(10);
    
    for(unsigned int i = 0; i < track_numbers.size(); i++){
        track_numbers[i] = 0;
    }
    
    load_tracks();
    start_playback();
}
Exemplo n.º 11
0
uint32_t nrfx_pwm_simple_playback(nrfx_pwm_t const * const p_instance,
                                  nrf_pwm_sequence_t const * p_sequence,
                                  uint16_t                   playback_count,
                                  uint32_t                   flags)
{
    pwm_control_block_t * p_cb  = &m_cb[p_instance->drv_inst_idx];
    NRFX_ASSERT(p_cb->state != NRFX_DRV_STATE_UNINITIALIZED);
    NRFX_ASSERT(playback_count > 0);
    NRFX_ASSERT(nrfx_is_in_ram(p_sequence->values.p_raw));

    // To take advantage of the looping mechanism, we need to use both sequences
    // (single sequence can be played back only once).
    nrf_pwm_sequence_set(p_instance->p_registers, 0, p_sequence);
    nrf_pwm_sequence_set(p_instance->p_registers, 1, p_sequence);
    bool odd = (playback_count & 1);
    nrf_pwm_loop_set(p_instance->p_registers,
        (playback_count / 2) + (odd ? 1 : 0));

    uint32_t shorts_mask;
    if (flags & NRFX_PWM_FLAG_STOP)
    {
        shorts_mask = NRF_PWM_SHORT_LOOPSDONE_STOP_MASK;
    }
    else if (flags & NRFX_PWM_FLAG_LOOP)
    {
        shorts_mask = odd ? NRF_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK
                          : NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK;
    }
    else
    {
        shorts_mask = 0;
    }
    nrf_pwm_shorts_set(p_instance->p_registers, shorts_mask);

    NRFX_LOG_INFO("Function: %s, sequence length: %d.",
                  __func__,
                  p_sequence->length);
    NRFX_LOG_DEBUG("Sequence data:");
    NRFX_LOG_HEXDUMP_DEBUG((uint8_t *)p_sequence->values.p_raw,
                           p_sequence->length * sizeof(uint16_t));
    return start_playback(p_instance, p_cb, flags,
        odd ? NRF_PWM_TASK_SEQSTART1 : NRF_PWM_TASK_SEQSTART0);
}
Exemplo n.º 12
0
static void
main_menu_background_update(void)
{
	update_background();

	if (eye_z > 50.f)
		eye_z -= .2f;

	++tics;

	if (menu_is_visible()) {
		if (highscore_spread > 0)
			highscore_spread--;

		if (menu_is_on_top_level(main_menu)) {
			if (++idle_tics > TICS_BEFORE_PLAYBACK)
				start_playback();
		}

		if (main_menu->spread < 0)
			main_menu->spread += 10.f;
	}
}
Exemplo n.º 13
0
int rzx_start_playback( const char *filename, int check_snapshot )
{
  utils_file file;
  libspectrum_error libspec_error; int error;
  libspectrum_snap* snap;

  if( rzx_recording ) return 1;

  rzx = libspectrum_rzx_alloc();

  error = utils_read_file( filename, &file );
  if( error ) return error;

  libspec_error = libspectrum_rzx_read( rzx, file.buffer, file.length );
  if( libspec_error != LIBSPECTRUM_ERROR_NONE ) {
    utils_close_file( &file );
    return libspec_error;
  }

  utils_close_file( &file );

  snap = rzx_get_initial_snapshot();
  if( !snap && check_snapshot ) {
    /* We need to load an external snapshot. Could be skipped if the snapshot
       is preloaded from command line */
    error = utils_open_snap();
    if( error ) return error;
  }

  error = start_playback( rzx );
  if( error ) {
    libspectrum_rzx_free( rzx );
    return error;
  }

  return 0;
}
void print_image(const char *filename, int freq_min, int freq_max, int col_time_ms)
{
    char buf[2048];
    Context context;
    int width, height, max;
    const char *image = read_pgm(filename, &width, &height, &max);
    if (image == NULL) {
        printf("Error loading %s", filename);
        exit(1);
    }
    Pa_Initialize();
    context_init(&context, height, freq_min, freq_max, col_time_ms);
    start_playback(&context);

    for (int col = 0; col < width; col++) {
        for (int row = 0; row < height; row++) {
            buf[height - 1 - row] = image[row*width + col];
        }
        print_image_column(&context, buf, height, max);
    }
    stop_playback(&context);
    Pa_Terminate();
    context_dealloc(&context);
}
Exemplo n.º 15
0
void nrf_drv_pwm_simple_playback(nrf_drv_pwm_t const * const p_instance,
                                 nrf_pwm_sequence_t const * p_sequence,
                                 uint16_t                   playback_count,
                                 uint32_t                   flags)
{
    pwm_control_block_t * p_cb  = &m_cb[p_instance->drv_inst_idx];
    ASSERT(p_cb->state != NRF_DRV_STATE_UNINITIALIZED);
    ASSERT(playback_count > 0);
    ASSERT(nrf_drv_is_in_RAM(p_sequence->values.p_raw));

    // To take advantage of the looping mechanism, we need to use both sequences
    // (single sequence can be played back only once).
    nrf_pwm_sequence_set(p_instance->p_registers, 0, p_sequence);
    nrf_pwm_sequence_set(p_instance->p_registers, 1, p_sequence);
    bool odd = (playback_count & 1);
    nrf_pwm_loop_set(p_instance->p_registers, playback_count / 2 + (odd ? 1 : 0));

    uint32_t shorts_mask;
    if (flags & NRF_DRV_PWM_FLAG_STOP)
    {
        shorts_mask = NRF_PWM_SHORT_LOOPSDONE_STOP_MASK;
    }
    else if (flags & NRF_DRV_PWM_FLAG_LOOP)
    {
        shorts_mask = odd ? NRF_PWM_SHORT_LOOPSDONE_SEQSTART1_MASK
                          : NRF_PWM_SHORT_LOOPSDONE_SEQSTART0_MASK;
    }
    else
    {
        shorts_mask = 0;
    }
    nrf_pwm_shorts_set(p_instance->p_registers, shorts_mask);

    start_playback(p_instance, p_cb, flags, odd ? NRF_PWM_TASK_SEQSTART1
                                                : NRF_PWM_TASK_SEQSTART0);
}
Exemplo n.º 16
0
//this is for handling query commands that need a response.
void handle_query(byte cmd)
{
  //which one did we get?
  switch (cmd)
  {
    //WORKS
    case HOST_CMD_VERSION:
      //get our host version
      host_version = hostPacket.get_16(1);

      //send our version back.
      hostPacket.add_16(FIRMWARE_VERSION);
      break;

    //WORKS
    case HOST_CMD_INIT:
      //just initialize
      initialize();
      break;

    case HOST_CMD_GET_BUFFER_SIZE:
      //send our remaining buffer size.
      hostPacket.add_16(commandBuffer.remainingCapacity());
      break;

    case HOST_CMD_CLEAR_BUFFER:
      //just clear it.
      commandBuffer.clear();
      break;

    case HOST_CMD_GET_POSITION:
      //send our position
      {
	const LongPoint& c = get_position();
	hostPacket.add_32(c.x);
	hostPacket.add_32(c.y);
	hostPacket.add_32(c.z);
      }
      hostPacket.add_8(get_endstop_states());
      break;

    case HOST_CMD_GET_RANGE:
      //get our range
      {
	const LongPoint& range = get_range();
	hostPacket.add_32(range.x);
	hostPacket.add_32(range.y);
	hostPacket.add_32(range.z);
      }
      break;

    case HOST_CMD_SET_RANGE:
      //set our range to what the host tells us
      set_range(LongPoint(
			  (long)hostPacket.get_32(1),
			  (long)hostPacket.get_32(5),
			  (long)hostPacket.get_32(9)));
      break;

    case HOST_CMD_ABORT:
      //support a microcontrollers right to choice.
      abort_print();
      break;

    case HOST_CMD_PAUSE:
      if (is_machine_paused)
      {
        //unpause our machine.
        is_machine_paused = false;

        //unpause our tools
        set_tool_pause_state(false);

        //resume stepping.
	resume_stepping();
      }
      else
      {
        //pause our activity.
        is_machine_paused = true;

        //pause our tools
        set_tool_pause_state(true);

        //pause stepping
	pause_stepping();
      }
      break;

    case HOST_CMD_PROBE:
      //we dont support this yet.
      hostPacket.unsupported();
      break;

    //WORKS
    case HOST_CMD_TOOL_QUERY:
      send_tool_query(hostPacket);
      break;

  case HOST_CMD_IS_FINISHED:
    {
      bool finished = is_point_buffer_empty() && at_target() && commandBuffer.size() == 0;
      hostPacket.add_8(finished?1:0);
      break;
    }

  case HOST_CMD_READ_EEPROM:
    {
      const uint16_t offset = hostPacket.get_16(1);
      const uint8_t count = hostPacket.get_8(3);
      if (count > 16) {
	hostPacket.overflow();
      } else {
	for (uint8_t i = 0; i < count; i++) {
	  hostPacket.add_8(EEPROM.read(offset+i));
	}
      }
    }
    break;
  case HOST_CMD_WRITE_EEPROM:
    {
      uint16_t offset = hostPacket.get_16(1);
      uint8_t count = hostPacket.get_8(3);
      if (count > 16) {
	hostPacket.overflow();
      } else {
	for (uint8_t i = 0; i < count; i++) {
	  EEPROM.write(offset+i,hostPacket.get_8(4+i));
	}
	hostPacket.add_8(count);
      }
    }
    break;
  case HOST_CMD_CAPTURE_TO_FILE:
    {
      char filename[17];
      int i = 0;
      while (i < 16) {
	uint8_t c = hostPacket.get_8(i+1);
	if (c == 0) break;
	filename[i++] = c;
      }
      filename[i] = 0;
      hostPacket.add_8(start_capture(filename));
    }
    break;
  case HOST_CMD_END_CAPTURE:
    hostPacket.add_32(finish_capture());
    break;
  case HOST_CMD_PLAYBACK_CAPTURE:
    {
      char filename[17];
      int i = 0;
      while (i < 16) {
	uint8_t c = hostPacket.get_8(i+1);
	if (c == 0) break;
	filename[i++] = c;
      }
      filename[i] = 0;
      hostPacket.add_8(start_playback(filename));
    }
    break;
  case HOST_CMD_RESET:
    {
      wdt_enable(WDTO_500MS);
    }
    break;
  case HOST_CMD_NEXT_FILENAME:
    {
      uint8_t resetFlag = hostPacket.get_8(1);
      uint8_t rspCode = 0;
      if (resetFlag != 0) {
	rspCode = sd_scan_reset();
	if (rspCode != 0) {
	  hostPacket.add_8(rspCode);
	  hostPacket.add_8(0);
	  break;
	}
      }
      char fnbuf[16];
      rspCode = sd_scan_next(fnbuf,16);
      hostPacket.add_8(rspCode);
      uint8_t idx;
      for (idx = 0; (idx < 16) && (fnbuf[idx] != 0); idx++) {
	hostPacket.add_8(fnbuf[idx]);
      }
      hostPacket.add_8(0);
    }
    break;
  default:
      hostPacket.unsupported();
  }
}
Exemplo n.º 17
0
static ALCboolean opensles_reset_playback(ALCdevice *pDevice)
{
    if (pDevice == NULL) {
        LOGE("Received a NULL ALCdevice! Returning ALC_FALSE from opensles_reset_playback");
        return ALC_FALSE;
    }
    LOGV("opensles_reset_playback pDevice=%p", pDevice);
    opesles_data_t *devState;
    unsigned bits = BytesFromDevFmt(pDevice->FmtType) * 8;
    unsigned channels = ChannelsFromDevFmt(pDevice->FmtChans);
    unsigned samples = pDevice->UpdateSize;
    unsigned size = samples * channels * bits / 8;
	SLuint32 sampling_rate = pDevice->Frequency * 1000;
	SLresult result;
    LOGV("bits=%u, channels=%u, samples=%u, size=%u, freq=%u", bits, channels, samples, size, pDevice->Frequency);
    if (pDevice->Frequency <= 22050) {
        bufferSize = defaultBufferSize / 2;
    }

    devState = (opesles_data_t *) pDevice->ExtraData;

    // create buffer queue audio player

    // configure audio source
    SLDataLocator_AndroidSimpleBufferQueue loc_bufq = {SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2};
//    SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, 2, SL_SAMPLINGRATE_44_1,
    SLDataFormat_PCM format_pcm = {SL_DATAFORMAT_PCM, 2, sampling_rate,
        SL_PCMSAMPLEFORMAT_FIXED_16, SL_PCMSAMPLEFORMAT_FIXED_16,
        SL_SPEAKER_FRONT_LEFT|SL_SPEAKER_FRONT_RIGHT, SL_BYTEORDER_LITTLEENDIAN};
    SLDataSource audioSrc = {&loc_bufq, &format_pcm};

    // configure audio sink
    SLDataLocator_OutputMix loc_outmix = {SL_DATALOCATOR_OUTPUTMIX, outputMixObject};
    SLDataSink audioSnk = {&loc_outmix, NULL};

    // create audio player
    LOGV("create audio player");
    const SLInterfaceID ids[1] = {*pSL_IID_ANDROIDSIMPLEBUFFERQUEUE};
    const SLboolean req[1] = {SL_BOOLEAN_TRUE};
    result = (*engineEngine)->CreateAudioPlayer(engineEngine, &devState->bqPlayerObject, &audioSrc, &audioSnk,
        1, ids, req);
    if ((result != SL_RESULT_SUCCESS) || (devState->bqPlayerObject == NULL)) {
        RELEASE_LOG("create audio player is null or errored: %lx", result);
        return ALC_FALSE;
    }

    // realize the player
    result = (*devState->bqPlayerObject)->Realize(devState->bqPlayerObject, SL_BOOLEAN_FALSE);
    assert(SL_RESULT_SUCCESS == result);

    // get the play interface
    result = (*devState->bqPlayerObject)->GetInterface(devState->bqPlayerObject, *pSL_IID_PLAY, &devState->bqPlayerPlay);
    assert(SL_RESULT_SUCCESS == result);

    // get the buffer queue interface
    result = (*devState->bqPlayerObject)->GetInterface(devState->bqPlayerObject, *pSL_IID_BUFFERQUEUE,
            &devState->bqPlayerBufferQueue);
    if ((result != SL_RESULT_SUCCESS) || (devState->bqPlayerBufferQueue == NULL)) {
        RELEASE_LOG("get the buffer queue interface is null or errored: %lx", result);
        return ALC_FALSE;
    }

    // register callback on the buffer queue
    result = (*devState->bqPlayerBufferQueue)->RegisterCallback(devState->bqPlayerBufferQueue, opensles_callback, (void *) pDevice);
    assert(SL_RESULT_SUCCESS == result);

    // playback_lock = createThreadLock();
    start_playback(pDevice);

    // set the player's state to playing
    result = (*devState->bqPlayerPlay)->SetPlayState(devState->bqPlayerPlay, SL_PLAYSTATE_PLAYING);
    assert(SL_RESULT_SUCCESS == result);

    // enqueue the first buffer to kick off the callbacks
    result = (*devState->bqPlayerBufferQueue)->Enqueue(devState->bqPlayerBufferQueue, "\0", 1);
    assert(SL_RESULT_SUCCESS == result);


    SetDefaultWFXChannelOrder(pDevice);
    devlist_add(pDevice);

    return ALC_TRUE;
}