void SpekerTestWdg::OnStartTest() { m_WaveFile.WavRead("test.wav"); int i = m_WaveFile.head.samplerate; m_HasRead = 0; StopAudio(); StartAudio(); }
void DirectSoundDriver::SetFrequency(uint32_t Frequency, uint32_t BufferSize) { WriteTrace(TraceAudioDriver, TraceDebug, "Start (Frequency: 0x%08X)", Frequency); StopAudio(); m_LOCK_SIZE = (BufferSize * 2); SetSegmentSize(m_LOCK_SIZE, Frequency); StartAudio(); WriteTrace(TraceAudioDriver, TraceDebug, "Done"); }
void SoundDriverBase::AI_Startup() { WriteTrace(TraceAudioDriver, TraceDebug, "Start"); m_AI_DMAPrimaryBytes = m_AI_DMASecondaryBytes = 0; m_AI_DMAPrimaryBuffer = m_AI_DMASecondaryBuffer = NULL; m_MaxBufferSize = MAX_SIZE; m_CurrentReadLoc = m_CurrentWriteLoc = m_BufferRemaining = 0; if (Initialize()) { StartAudio(); } WriteTrace(TraceAudioDriver, TraceDebug, "Start"); }
void AudioPluginOSX::AddBuffer(void * ptr, u32 length) { if (length == 0) return; if (mAudioThread == kInvalidThreadHandle) StartAudio(); u32 num_samples = length / sizeof( Sample ); mAudioBuffer.AddSamples( reinterpret_cast<const Sample *>(ptr), num_samples, mFrequency, kOutputFrequency ); u32 remaining_samples = mAudioBuffer.GetNumBufferedSamples(); mBufferLenMs = (1000 * remaining_samples) / kOutputFrequency; float ms = (float)num_samples * 1000.f / (float)mFrequency; DPF_AUDIO("Queuing %d samples @%dHz - %.2fms - bufferlen now %d\n", num_samples, mFrequency, ms, mBufferLenMs); }
HRESULT DSCapture::SetAudioFormat( DWORD dwPreferredSamplesPerSec, WORD wPreferredBitsPerSample, WORD nPreferredChannels ) { StopAudio(); ds_audio_graph_->Destroy(); ds_audio_cap_device_->SetPreferredSamplesPerSec( dwPreferredSamplesPerSec ); ds_audio_cap_device_->SetPreferredBitsPerSample( wPreferredBitsPerSample ); ds_audio_cap_device_->SetPreferredChannels( nPreferredChannels ); HRESULT hr = ds_audio_graph_->Create( ds_audio_cap_device_ ); if( FAILED( hr ) ) { return hr; } StartAudio(); return 0; }
static void PlayGame() { Uint8 *keystate; int quit = 0; int turn; int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */ int awaiting_respawn = 0; /* framerate counter variables */ int start_time, end_time; int frames_drawn = 0; /* respawn timer */ int respawn_timer = -1; prev_ticks = SDL_GetTicks(); start_time = time(NULL); /* Reset the score counters. */ player.score = 0; opponent.score = 0; /* Start sound playback. */ StartAudio(); StartMusic(); /* Start the music update thread. */ music_update_thread = SDL_CreateThread(UpdateMusicThread, NULL); if (music_update_thread == NULL) { printf("Unable to start music update thread.\n"); } /* Start the game! */ while ((quit == 0) && network_ok) { /* Determine how many milliseconds have passed since the last frame, and update our motion scaling. */ prev_ticks = cur_ticks; cur_ticks = SDL_GetTicks(); time_scale = (double)(cur_ticks-prev_ticks)/30.0; /* Update SDL's internal input state information. */ SDL_PumpEvents(); /* Grab a snapshot of the keyboard. */ keystate = SDL_GetKeyState(NULL); /* Lock the mutex so we can access the player's data. */ SDL_LockMutex(player_mutex); /* If this is a network game, take note of variables set by the network thread. These are handled differently for a scripted opponent. */ if (opponent_type == OPP_NETWORK) { /* Has the opponent respawned? */ if (network_opponent_respawn) { printf("Remote player has respawned.\n"); opponent.shields = 100; network_opponent_respawn = 0; awaiting_respawn = 0; } /* Has the local player been hit? */ if (local_player_hit) { local_player_hit--; player.shields -= PHASER_DAMAGE; ShowPhaserHit(&player); /* No need to check for death, the other computer will tell us. */ } } /* Update phasers. */ player.firing -= time_scale; if (player.firing < 0) player.firing = 0; opponent.firing -= time_scale; if (opponent.firing < 0) opponent.firing = 0; ChargePhasers(&player); /* If the local player is destroyed, the respawn timer will start counting. During this time the controls are disabled and explosion sequence occurs. */ if (respawn_timer >= 0) { respawn_timer++; if (respawn_timer >= ((double)RESPAWN_TIME / time_scale)) { respawn_timer = -1; InitPlayer(&player); /* Set the local_player_respawn flag so the network thread will notify the opponent of the respawn. */ local_player_respawn = 1; SetStatusMessage("GOOD LUCK, WARRIOR!"); } } /* Respond to input and network events, but not if we're in a respawn. */ if (respawn_timer == -1) { if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1; /* Left and right arrow keys control turning. */ turn = 0; if (keystate[SDLK_LEFT]) turn += 10; if (keystate[SDLK_RIGHT]) turn -= 10; /* Forward and back arrow keys activate thrusters. */ player.accel = 0; if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST; if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST; /* Spacebar fires phasers. */ if (keystate[SDLK_SPACE]) { if (CanPlayerFire(&player)) { FirePhasers(&player); /* If it's a hit, either notify the opponent or exact the damage. Create a satisfying particle burst. */ if (!awaiting_respawn && CheckPhaserHit(&player,&opponent)) { ShowPhaserHit(&opponent); DamageOpponent(); /* If that killed the opponent, set the "awaiting respawn" state, to prevent multiple kills. */ if (opponent.shields <= 0 && opponent_type == OPP_NETWORK) awaiting_respawn = 1; } } } /* Turn. */ player.angle += turn * time_scale; if (player.angle < 0) player.angle += 360; if (player.angle >= 360) player.angle -= 360; /* If this is a network game, the remote player will tell us if we've died. Otherwise we have to check for failed shields. */ if (((opponent_type == OPP_NETWORK) && local_player_dead) || (player.shields <= 0)) { printf("Local player has been destroyed.\n"); local_player_dead = 0; /* Kaboom! */ KillPlayer(); /* Respawn. */ respawn_timer = 0; } } /* If this is a player vs. computer game, give the computer a chance. */ if (opponent_type == OPP_COMPUTER) { if (RunGameScript() != 0) { fprintf(stderr, "Ending game due to script error.\n"); quit = 1; } /* Check for phaser hits against the player. */ if (opponent.firing) { if (CheckPhaserHit(&opponent,&player)) { ShowPhaserHit(&player); player.shields -= PHASER_DAMAGE; /* Did that destroy the player? */ if (respawn_timer < 0 && player.shields <= 0) { KillPlayer(); respawn_timer = 0; } } } ChargePhasers(&opponent); UpdatePlayer(&opponent); } /* Update the player's position. */ UpdatePlayer(&player); /* Update the status information. */ SetPlayerStatusInfo(player.score, player.shields, player.charge); SetOpponentStatusInfo(opponent.score, opponent.shields); /* Make the camera follow the player (but impose limits). */ camera_x = player.world_x - SCREEN_WIDTH/2; camera_y = player.world_y - SCREEN_HEIGHT/2; if (camera_x < 0) camera_x = 0; if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH) camera_x = WORLD_WIDTH-SCREEN_WIDTH-1; if (camera_y < 0) camera_y = 0; if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT) camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1; /* Update the particle system. */ UpdateParticles(); /* Keep OpenAL happy. */ UpdateAudio(&player, &opponent); /* Redraw everything. */ DrawBackground(screen, camera_x, camera_y); DrawParallax(screen, camera_x, camera_y); DrawParticles(screen, camera_x, camera_y); if (opponent.firing) DrawPhaserBeam(&opponent, screen, camera_x, camera_y); if (player.firing) DrawPhaserBeam(&player, screen, camera_x, camera_y); if (respawn_timer < 0) DrawPlayer(&player); if (!awaiting_respawn) DrawPlayer(&opponent); UpdateStatusDisplay(screen); /* Release the mutex so the networking system can get it. It doesn't stay unlocked for very long, but the networking system should still have plenty of time. */ SDL_UnlockMutex(player_mutex); /* Flip the page. */ SDL_Flip(screen); frames_drawn++; } end_time = time(NULL); if (start_time == end_time) end_time++; /* Display the average framerate. */ printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n", frames_drawn, end_time-start_time, (float)frames_drawn/(float)(end_time-start_time)); /* Terminate the music update thread. */ if (music_update_thread != NULL) { SDL_KillThread(music_update_thread); music_update_thread = NULL; } /* Stop audio playback. */ StopAudio(); StopMusic(); }
void VideoWatcher::CaptureFinished() { QFuture<void> CaptureTask; static bool AudioStarted = false; // In debug mode, keep the audio and video playback in sync if (WaitDuration > 0) MCSleep(WaitDuration); FrameCount++; OverallFrameCount++; *OriginalImage = *CapturedImage; if (AudioStarted == false) { QTimer::singleShot(100, this, SIGNAL(StartAudio())); AudioStarted = true; } // Start a new capture CaptureTask = QtConcurrent::run(boost::bind(&VideoWatcher::CaptureImage, this)); CaptureWatcher.setFuture(CaptureTask); if (FrameCount % 3 == 1) return; OriginalImage->ConvertBGRToRGB(); *FinalImage = *OriginalImage; CheckFiles(); // Check if the capture process stopped by some reason if (!CaptureDevice->IsCapturing()) { MC_LOG("Capture stopped"); QCoreApplication::quit(); } // Be sure that the image has the expected size if (FinalImage->GetWidth() != FrameWidth && FinalImage->GetHeight() != FrameHeight) { FinalImage->Resize(FrameWidth, FrameHeight); } if (Undistort && FinalImage->GetWidth() == FrameWidth && FinalImage->GetHeight() == FrameHeight) { Calibration->Undistort(*FinalImage); // TODO: The rotational correction is too CPU expensive if (!MCIsFloatInfinity(RotationAngle)) { FinalImage->Rotate(RotationCenter.X, RotationCenter.Y, RotationAngle); } } // Check if the lights are off if (FinalImage->AverageBrightnessLevel() < 10) { Markers->Reset(); MotionDetection->Reset(); Q_EMIT(VideoEvent(IOP::IdleEvent)); Q_EMIT(VideoEvent(IOP::CaptureEvent)); return; } // Calculate fps if (FrameCount % 300 == 0) { MC_LOG("Capture speed: %1.2f fps", (float)1000 / FpsTimer.elapsed()*FrameCount); FpsTimer.start(); FrameCount = 0; MC_LOG("Average brightness level: %1.2f", FinalImage->AverageBrightnessLevel()); } // Corner detection Markers->AddImage(*FinalImage); // TODO: The rotational correction is too CPU expensive if (Markers->IsReady() && !Markers->IsAnyMissingCorner() && MCIsFloatInfinity(RotationAngle)) { // Get the rotational angle and reset the marker detection Markers->GetRotationalCorrection(*FinalImage, RotationAngle, RotationCenter); MC_LOG("Detected rotation: %1.2f degrees", RotationAngle); Markers->Reset(); } // Motion detection MEImage MotionFrame = *FinalImage; MotionFrame.Resize(FrameWidth / 4, FrameHeight / 4); MotionDetection->DetectMotions(MotionFrame); /* * Draw the debug signs and texts on the original image */ DebugMessageImage->Clear(); // Composite debug signs if (DebugMotions) { MEImage MaskImage; MotionDetection->GetMotionsMask(MaskImage); // Convert the grayscale image back to RGB MaskImage.ConvertToRGB(); MaskImage.Resize(FrameWidth, FrameHeight); FinalImage->Addition(MaskImage, ME::MaskAddition); } if (DebugCorners) Markers->DrawDebugSigns(*FinalImage); if (Markers->IsReady() && Markers->IsAnyMissingCorner()) { Markers->DrawMissingCorners(*FinalImage); DebugMessageImage->DrawText(160, 320, "Table not detected", 1, MEColor(255, 255, 255)); Q_EMIT(VideoEvent(IOP::MissingCornersEvent)); } Q_EMIT(VideoEvent(IOP::NormalEvent)); Q_EMIT(VideoEvent(IOP::CaptureEvent)); }
void FillBuffer ( int buffer ) { //void AddToBuffer (void *sndptr, DWORD sndlen); DWORD dwBytesLocked; VOID *lpvData; if (!audioIsPlaying) StartAudio(); if (gUcode != 4) if (Snd1Len == 0) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); return; } if (SndBuffer[buffer] == Buffer_Empty) { if (Snd1Len >= BufferSize) { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, BufferSize * buffer,BufferSize, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_Full; Snd1ReadPos += dwBytesLocked; Snd1Len -= dwBytesLocked; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } else { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, BufferSize * buffer,Snd1Len, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_HalfFull; Snd1ReadPos += dwBytesLocked; SpaceLeft = BufferSize - Snd1Len; Snd1Len = 0; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } } else if (SndBuffer[buffer] == Buffer_HalfFull) { if (Snd1Len >= SpaceLeft) { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, (BufferSize * (buffer + 1)) - SpaceLeft ,SpaceLeft, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_Full; Snd1ReadPos += dwBytesLocked; Snd1Len -= dwBytesLocked; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } else { if (FAILED( IDirectSoundBuffer8_Lock(lpdsbuf, (BufferSize * (buffer + 1)) - SpaceLeft,Snd1Len, &lpvData, &dwBytesLocked, NULL, NULL, 0 ) ) ) { IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); //DisplayError("FAILED lock"); return; } Soundmemcpy(lpvData,Snd1ReadPos,dwBytesLocked); //AddToBuffer (lpvData, dwBytesLocked); SndBuffer[buffer] = Buffer_HalfFull; Snd1ReadPos += dwBytesLocked; SpaceLeft = SpaceLeft - Snd1Len; Snd1Len = 0; IDirectSoundBuffer8_Unlock(lpdsbuf, lpvData, dwBytesLocked, NULL, 0 ); } } if (gUcode != 4) if ((Snd1Len == 0) /*&& (gUcode != UNDEFINED_UCODE)*/) { *AudioInfo.AI_STATUS_REG &= ~AI_STATUS_FIFO_FULL; *AudioInfo.MI_INTR_REG |= MI_INTR_AI; AudioInfo.CheckInterrupts(); } }
static void PlayGame() { Uint8 *keystate; int quit = 0; int turn; int prev_ticks = 0, cur_ticks = 0; /* for keeping track of timing */ /* framerate counter variables */ int start_time, end_time; int frames_drawn = 0; /* Start audio playback. */ StartAudio(); StartMusic(); /* Start the music update thread. */ music_update_thread = SDL_CreateThread(UpdateMusicThread, NULL); if (music_update_thread == NULL) { printf("Unable to start music update thread.\n"); } prev_ticks = SDL_GetTicks(); start_time = time(NULL); while (quit == 0) { /* Determine how many milliseconds have passed since the last frame, and update our motion scaling. */ prev_ticks = cur_ticks; cur_ticks = SDL_GetTicks(); time_scale = (double)(cur_ticks-prev_ticks)/30.0; /* Update SDL's internal input state information. */ SDL_PumpEvents(); /* Grab a snapshot of the keyboard. */ keystate = SDL_GetKeyState(NULL); /* Respond to input. */ if (keystate[SDLK_q] || keystate[SDLK_ESCAPE]) quit = 1; /* Left and right arrow keys control turning. */ turn = 0; if (keystate[SDLK_LEFT]) turn += 15; if (keystate[SDLK_RIGHT]) turn -= 15; /* Forward and back arrow keys activate thrusters. */ player.accel = 0; if (keystate[SDLK_UP]) player.accel = PLAYER_FORWARD_THRUST; if (keystate[SDLK_DOWN]) player.accel = PLAYER_REVERSE_THRUST; /* Spacebar slows the ship down. */ if (keystate[SDLK_SPACE]) { player.velocity *= 0.8; } /* Just an amusing way to test the particle system. */ if (keystate[SDLK_e]) { CreateParticleExplosion( player.world_x, player.world_y, 255, 255, 255, 10, 300); CreateParticleExplosion( player.world_x, player.world_y, 255, 0, 0, 5, 100); CreateParticleExplosion( player.world_x, player.world_y, 255, 255, 0, 2, 50); } /* Allow a turn of four degrees per frame. */ player.angle += turn * time_scale; if (player.angle < 0) player.angle += 360; if (player.angle >= 360) player.angle -= 360; /* Update the player's position. */ UpdatePlayer(&player); UpdatePlayer(&opponent); /* Make the camera follow the player (but impose limits). */ camera_x = player.world_x - SCREEN_WIDTH/2; camera_y = player.world_y - SCREEN_HEIGHT/2; if (camera_x < 0) camera_x = 0; if (camera_x >= WORLD_WIDTH-SCREEN_WIDTH) camera_x = WORLD_WIDTH-SCREEN_WIDTH-1; if (camera_y < 0) camera_y = 0; if (camera_y >= WORLD_HEIGHT-SCREEN_HEIGHT) camera_y = WORLD_HEIGHT-SCREEN_HEIGHT-1; /* Update the particle system. */ UpdateParticles(); /* Keep OpenAL happy. */ UpdateAudio(&player, &opponent); /* Redraw everything. */ DrawBackground(screen, camera_x, camera_y); DrawParallax(screen, camera_x, camera_y); DrawParticles(screen, camera_x, camera_y); DrawPlayer(&player); DrawPlayer(&opponent); /* Flip the page. */ SDL_Flip(screen); frames_drawn++; } end_time = time(NULL); if (start_time == end_time) end_time++; /* Display the average framerate. */ printf("Drew %i frames in %i seconds, for a framerate of %.2f fps.\n", frames_drawn, end_time-start_time, (float)frames_drawn/(float)(end_time-start_time)); /* Terminate the music update thread. */ if (music_update_thread != NULL) { SDL_KillThread(music_update_thread); music_update_thread = NULL; } /* Stop audio playback. */ StopAudio(); StopMusic(); }
_Use_decl_annotations_ VOID OnIoDeviceControl( WDFQUEUE Queue, WDFREQUEST Request, size_t OutputBufferLength, size_t InputBufferLength, ULONG IoControlCode ) /*++ Routine Description: This event handled device control calls. Arguments: Queue - Handle of the queue object associated with the request Request - Handle of the request object OutputBufferLength - length of the request's output buffer InputBufferLength - length of the request's input buffer IoControlCode - the driver-defined or system-defined I/O control code Return Value: None --*/ { UNREFERENCED_PARAMETER(OutputBufferLength); UNREFERENCED_PARAMETER(InputBufferLength); WDFDEVICE device; PDEVICE_CONTEXT deviceContext; NTSTATUS status = STATUS_SUCCESS; device = WdfIoQueueGetDevice(Queue); deviceContext = GetContext(device); // // Validate the IO code and exexute on it. // switch (IoControlCode) { case IOCTL_BCM_PWM_SET_CLOCKCONFIG: status = ValidateAndSetClockConfig(device, Request); break; case IOCTL_BCM_PWM_GET_CLOCKCONFIG: status = GetClockConfig(device, Request); break; case IOCTL_BCM_PWM_SET_CHANNELCONFIG: status = ValidateAndSetChannelConfig(device, Request); break; case IOCTL_BCM_PWM_GET_CHANNELCONFIG: status = GetChannelConfig(device, Request); break; case IOCTL_BCM_PWM_SET_DUTY_REGISTER: status = ValidateAndSetDutyRegister(device, Request); break; case IOCTL_BCM_PWM_GET_DUTY_REGISTER: status = GetDutyRegister(device, Request); break; case IOCTL_BCM_PWM_START: status = ValidateAndStartChannel(device, Request); break; case IOCTL_BCM_PWM_STOP: status = ValidateAndStopChannel(device, Request); break; case IOCTL_BCM_PWM_AQUIRE_AUDIO: status = AquireAudio(device); break; case IOCTL_BCM_PWM_RELEASE_AUDIO: status = ReleaseAudio(device); break; case IOCTL_BCM_PWM_INITIALIZE_AUDIO: status = InitializeAudio(device, Request); break; case IOCTL_BCM_PWM_REGISTER_AUDIO_NOTIFICATION: status = RegisterAudioNotification(device, Request); break; case IOCTL_BCM_PWM_UNREGISTER_AUDIO_NOTIFICATION: status = UnregisterAudioNotification(device, Request); break; case IOCTL_BCM_PWM_START_AUDIO: status = StartAudio(device); break; case IOCTL_BCM_PWM_PAUSE_AUDIO: status = PauseAudio(device); break; case IOCTL_BCM_PWM_RESUME_AUDIO: status = ResumeAudio(device); break; case IOCTL_BCM_PWM_STOP_AUDIO: status = StopAudio(device); break; default: status = STATUS_INVALID_DEVICE_REQUEST; TraceEvents(TRACE_LEVEL_ERROR, TRACE_IOCTL, "Unexpected IO code in request. Request: 0x%08x, Code: 0x%08x", (ULONG)Request, IoControlCode); break; } WdfRequestComplete(Request, status); }