@@ -111,8 +111,7 @@ namespace ISOBMFF
111111 stream.ReadUInt16 ();
112112
113113 // template unsigned int(32) samplerate = { default samplerate of media } << 16;
114- uint32_t sampleRateFixed = stream.ReadBigEndianUInt32 ();
115- SetSampleRate ( (sampleRateFixed >> 16 ) + ((sampleRateFixed & 0xFFFF ) / 65536 ) );
114+ SetSampleRateRaw ( stream.ReadBigEndianUInt32 () );
116115
117116 container.ReadData ( parser, stream );
118117 this ->impl ->_boxes = container.GetBoxes ();
@@ -124,6 +123,7 @@ namespace ISOBMFF
124123
125124 props.push_back ( { " Channel Count" , std::to_string (this ->GetChannelCount ()) } );
126125 props.push_back ( { " Sample Size" , std::to_string (this ->GetSampleSize ()) } );
126+ props.push_back ( { " Sample Rate (raw)" , std::to_string (this ->GetSampleRateRaw ()) } );
127127 props.push_back ( { " Sample Rate" , std::to_string (this ->GetSampleRate ()) } );
128128
129129 return props;
@@ -145,11 +145,25 @@ namespace ISOBMFF
145145 return this ->impl ->_samplesize ;
146146 }
147147
148- uint32_t MP4A::GetSampleRate () const
148+ uint32_t MP4A::GetSampleRateRaw () const
149149 {
150150 return this ->impl ->_samplerate ;
151151 }
152152
153+ float MP4A::GetSampleRate () const
154+ {
155+ uint32_t sampleRateFixed = this ->GetSampleRateRaw ();
156+ // Read Sample Rate:
157+ // The sample rate is stored as a 16.16 fixed-point number (32 bits).
158+ // The integer part is obtained by shifting the value right by 16 bits
159+ // (>> 16).
160+ float sampleRate = (sampleRateFixed >> 16 );
161+ // The fractional part is obtained by masking the lower 16 bits
162+ // (& 0xFFFF) and dividing by 65536.0.
163+ sampleRate += ((sampleRateFixed & 0xffff ) / 65536.0 );
164+ return sampleRate;
165+ }
166+
153167 void MP4A::SetChannelCount ( uint16_t channelcount )
154168 {
155169 this ->impl ->_channelcount = channelcount;
@@ -160,7 +174,7 @@ namespace ISOBMFF
160174 this ->impl ->_samplesize = samplesize;
161175 }
162176
163- void MP4A::SetSampleRate ( uint32_t samplerate )
177+ void MP4A::SetSampleRateRaw ( uint32_t samplerate )
164178 {
165179 this ->impl ->_samplerate = samplerate;
166180 }
0 commit comments