int kqt_Handle_set_position(kqt_Handle handle, int track, long long nanoseconds) { check_handle(handle, 0); Handle* h = get_handle(handle); check_data_is_valid(h, 0); check_data_is_validated(h, 0); if (track < -1 || track >= KQT_TRACKS_MAX) { Handle_set_error(h, ERROR_ARGUMENT, "Invalid track number: %d", track); return 0; } if (nanoseconds < 0) { Handle_set_error(h, ERROR_ARGUMENT, "nanoseconds must be non-negative"); return 0; } int64_t skip_frames = (int64_t)(((double)nanoseconds / 1000000000L) * Player_get_audio_rate(h->player)); Device_states_reset(Player_get_device_states(h->player)); Player_reset(h->player, track); Player_skip(h->player, skip_frames); return 1; }
long long kqt_Handle_get_duration(kqt_Handle handle, int track) { check_handle(handle, -1); Handle* h = get_handle(handle); check_data_is_valid(h, -1); check_data_is_validated(h, -1); if (track < -1 || track >= KQT_TRACKS_MAX) { Handle_set_error(h, ERROR_ARGUMENT, "Invalid track number: %d", track); return -1; } Player_reset(h->length_counter, track); Player_skip(h->length_counter, KQT_CALC_DURATION_MAX); return Player_get_nanoseconds(h->length_counter); }
bool Handle_init(Handle* handle) { rassert(handle != NULL); handle->data_is_valid = true; handle->data_is_validated = true; handle->update_connections = false; handle->module = NULL; handle->error = *ERROR_AUTO; handle->validation_error = *ERROR_AUTO; memset(handle->position, '\0', POSITION_LENGTH); handle->player = NULL; handle->length_counter = NULL; // int buffer_count = SONG_DEFAULT_BUF_COUNT; // int voice_count = 256; handle->module = new_Module(); if (handle->module == NULL) { Handle_set_error(NULL, ERROR_MEMORY, "Couldn't allocate memory"); Handle_deinit(handle); return false; } // Create players handle->player = new_Player( handle->module, DEFAULT_AUDIO_RATE, 2048, 16384, 1024); handle->length_counter = new_Player(handle->module, 1000000000L, 0, 0, 0); if (handle->player == NULL || handle->length_counter == NULL) { Handle_set_error(NULL, ERROR_MEMORY, "Couldn't allocate memory"); Handle_deinit(handle); return false; } Player_reset(handle->player, -1); return true; }