Mercurial > foo_out_sdl
comparison foosdk/sdk/foobar2000/SDK/replaygain_scanner.h @ 1:20d02a178406 default tip
*: check in everything else
yay
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 05 Jan 2026 02:15:46 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:e9bb126753e7 | 1:20d02a178406 |
|---|---|
| 1 #pragma once | |
| 2 | |
| 3 #include "replaygain.h" | |
| 4 | |
| 5 //! Container of ReplayGain scan results from one or more tracks. | |
| 6 class replaygain_result : public service_base { | |
| 7 FB2K_MAKE_SERVICE_INTERFACE(replaygain_result, service_base); | |
| 8 public: | |
| 9 //! Retrieves the gain value, in dB. | |
| 10 virtual float get_gain() = 0; | |
| 11 //! Retrieves the peak value, normalized to 0..1 range (audio_sample value). | |
| 12 virtual float get_peak() = 0; | |
| 13 //! Merges ReplayGain scan results from different tracks. Merge results from all tracks in an album to get album gain/peak values. \n | |
| 14 //! This function returns a newly created replaygain_result object. Existing replaygain_result objects remain unaltered. | |
| 15 virtual replaygain_result::ptr merge(replaygain_result::ptr other) = 0; | |
| 16 | |
| 17 replaygain_info make_track_info() { | |
| 18 replaygain_info ret = replaygain_info_invalid; ret.m_track_gain = this->get_gain(); ret.m_track_peak = this->get_peak(); return ret; | |
| 19 } | |
| 20 }; | |
| 21 | |
| 22 //! Instance of a ReplayGain scanner. \n | |
| 23 //! Use replaygain_scanner_entry::instantiate() to create a replaygain_scanner object; see replaygain_scanner_entry for more info. \n | |
| 24 //! Typical use: call process_chunk() with each chunk read from your track, call finalize() to obtain results for this track and reset replaygain_scanner's state for scanning another track; to obtain album gain/peak values, merge results (replaygain_result::merge) from all tracks. \n | |
| 25 class replaygain_scanner : public service_base { | |
| 26 FB2K_MAKE_SERVICE_INTERFACE(replaygain_scanner, service_base); | |
| 27 public: | |
| 28 //! Processes a PCM chunk. \n | |
| 29 //! May throw exception_io_data if the chunk contains something that can't be processed properly. | |
| 30 virtual void process_chunk(const audio_chunk & chunk) = 0; | |
| 31 //! Finalizes the scanning process; resets scanner's internal state and returns results for the track we've just scanned. \n | |
| 32 //! After calling finalize(), scanner's state becomes the same as after instantiation; you can continue with processing another track without creating a new scanner object. | |
| 33 virtual replaygain_result::ptr finalize() = 0; | |
| 34 }; | |
| 35 | |
| 36 | |
| 37 //! Entrypoint class for instantiating replaygain_scanner objects. \n | |
| 38 //! This service is OPTIONAL; it's available from foobar2000 0.9.5.3 up but only if the ReplayGain Scanner component is installed. \n | |
| 39 //! It is recommended that you use replaygain_scanner like this: \n | |
| 40 //! replaygain_scanner_entry::ptr theAPI; \n | |
| 41 //! if (replaygain_scanner_entry::tryGet(theAPI)) { \n | |
| 42 //! myInstance = theAPI->instantiate(); \n | |
| 43 //! } else { \n | |
| 44 //! no foo_rgscan installed - complain/fail/etc \n | |
| 45 //! } \n | |
| 46 //! Note that replaygain_scanner_entry::get() is provided for convenience - it WILL crash with no foo_rgscan present. Use it only after prior checks. | |
| 47 class replaygain_scanner_entry : public service_base { | |
| 48 FB2K_MAKE_SERVICE_COREAPI(replaygain_scanner_entry); | |
| 49 public: | |
| 50 //! Instantiates a replaygain_scanner object. | |
| 51 virtual replaygain_scanner::ptr instantiate() = 0; | |
| 52 | |
| 53 //! Helper; uses replaygain_scanner_entry_v2 if available; see replaygain_scanner_entry_v2. | |
| 54 replaygain_scanner::ptr instantiate( uint32_t flags ); | |
| 55 }; | |
| 56 | |
| 57 //! \since 1.4 | |
| 58 //! This service is OPTIONAL; it's available from foobar2000 v1.4 up but only if the ReplayGain Scanner component is installed. \n | |
| 59 //! Use tryGet() to instantiate - get() only after prior verification of availability. | |
| 60 class replaygain_scanner_entry_v2 : public replaygain_scanner_entry { | |
| 61 FB2K_MAKE_SERVICE_COREAPI_EXTENSION(replaygain_scanner_entry_v2, replaygain_scanner_entry) | |
| 62 public: | |
| 63 enum { | |
| 64 flagScanPeak = 1 << 0, | |
| 65 flagScanGain = 1 << 1, | |
| 66 }; | |
| 67 | |
| 68 //! Extended instantiation method. \n | |
| 69 //! Allows you to declare which parts of the scanning process are relevant for you | |
| 70 //! so irrelevant parts of the processing can be skipped. | |
| 71 //! For an example, if you don't care about the peak, specify only flagScanGain - | |
| 72 //! as peak scan while normally cheap may be very expensive with extreme oversampling specified by user. | |
| 73 virtual replaygain_scanner::ptr instantiate(uint32_t flags) = 0; | |
| 74 }; | |
| 75 | |
| 76 //! Internal service introduced in 1.5. No guarantees about compatibility. May be changed or removed at any time. | |
| 77 class replaygain_scanner_config : public service_base { | |
| 78 FB2K_MAKE_SERVICE_COREAPI(replaygain_scanner_config); | |
| 79 public: | |
| 80 virtual void get_album_pattern( pfc::string_base & out ) = 0; | |
| 81 virtual uint64_t get_read_size_bytes() = 0; | |
| 82 }; | |
| 83 | |
| 84 #ifdef FOOBAR2000_DESKTOP | |
| 85 //! \since 1.4 | |
| 86 //! A class for applying gain to compressed audio packets such as MP3 or AAC. \n | |
| 87 //! Implemented by foo_rgscan for common formats. May be extended to allow foo_rgscan to manipulate more different codecs. | |
| 88 class replaygain_alter_stream : public service_base { | |
| 89 FB2K_MAKE_SERVICE_INTERFACE(replaygain_alter_stream, service_base) | |
| 90 public: | |
| 91 //! @returns The amount to which all adjustments are quantized for this format. Essential for caller to be able to correctly prevent clipping. | |
| 92 virtual float get_adjustment_step( ) = 0; | |
| 93 //! Sets the adjustment in decibels. Note that the actual applied adjustment will be quantized with nearest-rounding to a multiple of get_adjustment_step() value. | |
| 94 virtual void set_adjustment( float deltaDB ) = 0; | |
| 95 //! Passes the first frame playload. This serves as a hint and may be safely ignored for most formats. However in some cases - MP3 vs MP2 in particular - you do knot know what exact format you're dealing with until you've examined the first frame. \n | |
| 96 //! If you're calling this service, always feed the first frame before calling get_adjustment_step(). | |
| 97 virtual void on_first_frame( const void * frame, size_t bytes ) = 0; | |
| 98 //! Applies gain to the frame. \n | |
| 99 //! May throw exception_io_data if the frame payload is corrupted and cannot be altered. The user will be informed about bad frame statistics, however the operation will continue until EOF. | |
| 100 virtual void alter_frame( void * frame, size_t bytes ) = 0; | |
| 101 }; | |
| 102 | |
| 103 //! \since 1.4 | |
| 104 //! Entrypoint class for instantiating replaygain_alter_stream. Walk with service_enum_t<> to find one that supports specific format. | |
| 105 class replaygain_alter_stream_entry : public service_base { | |
| 106 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(replaygain_alter_stream_entry); | |
| 107 public: | |
| 108 //! @returns Newly created replaygain_alter_stream object. Null if this format is not supported by this implementation. | |
| 109 //! Arguments as per packet_decoder::g_open(). | |
| 110 virtual replaygain_alter_stream::ptr open(const GUID & p_owner, size_t p_param1, const void * p_param2, size_t p_param2size ) = 0; | |
| 111 }; | |
| 112 #endif |
