neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
audio_instrument.hpp
Go to the documentation of this file.
1// audio_instrument.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2021 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include <neogfx/neogfx.hpp>
24
25#pragma once
26
27namespace neogfx
28{
29 class audio_instrument : public audio_bitstream<i_audio_instrument>
30 {
31 public:
32 audio_instrument(audio_sample_rate aSampleRate, neogfx::instrument aInstrument, float aAmplitude = 1.0f);
33 audio_instrument(i_audio_device const& aDevice, neogfx::instrument aInstrument, float aAmplitude = 1.0f);
34 public:
35 time_point play_note(note aNote, std::chrono::duration<double> const& aDuration, float aAmplitude = 1.0f) final;
36 time_point play_note(std::chrono::duration<double> const& aWhen, note aNote, std::chrono::duration<double> const& aDuration, float aAmplitude = 1.0f) final;
37 time_point play_note(time_point aWhen, note aNote, std::chrono::duration<double> const& aDuration, float aAmplitude = 1.0f) final;
38 time_point rest(std::chrono::duration<double> const& aDuration) final;
39 public:
41 void generate(audio_channel aChannel, audio_frame_count aFrameCount, float* aOutputFrames) final;
42 void generate_from(audio_channel aChannel, audio_frame_index aFrameFrom, audio_frame_count aFrameCount, float* aOutputFrames) final;
43 private:
44 neogfx::instrument iInstrument;
45 time_point iInputCursor = 0ULL;
46 time_point iOutputCursor = 0ULL;
47 struct part
48 {
49 std::optional<note> note;
50 std::optional<time_interval> noteLength;
51 std::optional<float> amplitude;
52 time_interval start;
53 time_interval duration;
54 };
55 std::vector<part> iComposition;
56 };
57}
time_point play_note(note aNote, std::chrono::duration< double > const &aDuration, float aAmplitude=1.0f) final
audio_instrument(i_audio_device const &aDevice, neogfx::instrument aInstrument, float aAmplitude=1.0f)
time_point rest(std::chrono::duration< double > const &aDuration) final
void generate(audio_channel aChannel, audio_frame_count aFrameCount, float *aOutputFrames) final
audio_instrument(audio_sample_rate aSampleRate, neogfx::instrument aInstrument, float aAmplitude=1.0f)
void generate_from(audio_channel aChannel, audio_frame_index aFrameFrom, audio_frame_count aFrameCount, float *aOutputFrames) final
std::uint64_t audio_frame_index
basic_length< default_geometry_value_type > length
Definition units.hpp:926
std::uint64_t audio_frame_count
std::uint64_t audio_sample_rate
scalar time_interval
Definition chrono.hpp:55
Definition plf_hive.h:79