diff --git a/Plugins/Opus/Opus/OpusDecoder.h b/Plugins/Opus/Opus/OpusDecoder.h index df3b34346..60a8a5cff 100644 --- a/Plugins/Opus/Opus/OpusDecoder.h +++ b/Plugins/Opus/Opus/OpusDecoder.h @@ -30,6 +30,9 @@ int channels; long totalFrames; + double track_gain; + double album_gain; + NSString *genre; NSString *album; NSString *artist; diff --git a/Plugins/Opus/Opus/OpusDecoder.m b/Plugins/Opus/Opus/OpusDecoder.m index 7390e1c95..5f9e62c59 100644 --- a/Plugins/Opus/Opus/OpusDecoder.m +++ b/Plugins/Opus/Opus/OpusDecoder.m @@ -104,15 +104,17 @@ opus_int64 sourceTell(void *_stream) { totalFrames = op_pcm_total(opusRef, -1); - NSString *gainMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"volumeScaling"]; - BOOL isAlbum = [gainMode hasPrefix:@"albumGain"]; - BOOL isTrack = [gainMode hasPrefix:@"trackGain"]; + const OpusHead *head = op_head(opusRef, -1); + const OpusTags *tags = op_tags(opusRef, -1); - if(isAlbum || isTrack) { - op_set_gain_offset(opusRef, isAlbum ? OP_HEADER_GAIN : OP_TRACK_GAIN, 0); - } else { - op_set_gain_offset(opusRef, OP_ABSOLUTE_GAIN, 0); - } + int _track_gain = 0; + + opus_tags_get_track_gain(tags, &_track_gain); + + album_gain = ((double)head->output_gain / 256.0) + 5.0; + track_gain = ((double)_track_gain / 256.0) + album_gain; + + op_set_gain_offset(opusRef, OP_ABSOLUTE_GAIN, 0); [self willChangeValueForKey:@"properties"]; [self didChangeValueForKey:@"properties"]; @@ -268,16 +270,18 @@ opus_int64 sourceTell(void *_stream) { } - (NSDictionary *)properties { - return @{@"channels": [NSNumber numberWithInt:channels], - @"bitsPerSample": [NSNumber numberWithInt:32], - @"floatingPoint": [NSNumber numberWithBool:YES], - @"sampleRate": [NSNumber numberWithFloat:48000], - @"totalFrames": [NSNumber numberWithDouble:totalFrames], - @"bitrate": [NSNumber numberWithInt:bitrate], - @"seekable": [NSNumber numberWithBool:([source seekable] && seekable)], - @"codec": @"Opus", - @"endian": @"host", - @"encoding": @"lossy"}; + return @{ @"channels": [NSNumber numberWithInt:channels], + @"bitsPerSample": [NSNumber numberWithInt:32], + @"floatingPoint": [NSNumber numberWithBool:YES], + @"sampleRate": [NSNumber numberWithFloat:48000], + @"totalFrames": [NSNumber numberWithDouble:totalFrames], + @"bitrate": [NSNumber numberWithInt:bitrate], + @"seekable": [NSNumber numberWithBool:([source seekable] && seekable)], + @"replayGainTrackGain": [NSNumber numberWithFloat:track_gain], + @"replayGainAlbumGain": [NSNumber numberWithFloat:album_gain], + @"codec": @"Opus", + @"endian": @"host", + @"encoding": @"lossy" }; } - (NSDictionary *)metadata {