1 // Copyright (c) 2010, Niels Martin Hansen 2 // All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions are met: 6 // 7 // * Redistributions of source code must retain the above copyright notice, 8 // this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above copyright notice, 10 // this list of conditions and the following disclaimer in the documentation 11 // and/or other materials provided with the distribution. 12 // * Neither the name of the Aegisub Group nor the names of its contributors 13 // may be used to endorse or promote products derived from this software 14 // without specific prior written permission. 15 // 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 20 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 // POSSIBILITY OF SUCH DAMAGE. 27 // 28 // Aegisub Project http://www.aegisub.org/ 29 30 #include "audio_renderer.h" 31 32 #include <memory> 33 #include <vector> 34 35 class AudioColorScheme; 36 class wxArrayString; 37 38 /// Render a waveform display of PCM audio data 39 class AudioWaveformRenderer final : public AudioRendererBitmapProvider { 40 /// Colour tables used for rendering 41 std::vector<AudioColorScheme> colors; 42 43 /// Pre-allocated buffer for audio fetched from provider 44 std::unique_ptr<char[]> audio_buffer; 45 46 /// Whether to render max+avg or just max 47 bool render_averages; 48 OnSetProvider()49 void OnSetProvider() override { audio_buffer.reset(); } OnSetMillisecondsPerPixel()50 void OnSetMillisecondsPerPixel() override { audio_buffer.reset(); } 51 52 public: 53 /// @brief Constructor 54 /// @param color_scheme_name Name of the color scheme to use 55 AudioWaveformRenderer(std::string const& color_scheme_name); 56 57 /// @brief Destructor 58 ~AudioWaveformRenderer(); 59 60 /// @brief Render a range of audio waveform 61 /// @param bmp [in,out] Bitmap to render into, also carries length information 62 /// @param start First column of pixel data in display to render 63 /// @param style Style to render audio in 64 void Render(wxBitmap &bmp, int start, AudioRenderingStyle style) override; 65 66 /// @brief Render blank area 67 void RenderBlank(wxDC &dc, const wxRect &rect, AudioRenderingStyle style) override; 68 69 /// @brief Cleans up the cache 70 /// @param max_size Maximum size in bytes for the cache 71 /// 72 /// Does nothing for waveform renderer, since it does not have a backend cache AgeCache(size_t max_size)73 void AgeCache(size_t max_size) override { } 74 75 /// Get a list of waveform rendering modes 76 static wxArrayString GetWaveformStyles(); 77 }; 78