qiaohaijiao commented on code in PR #7717:
URL: https://github.com/apache/nuttx/pull/7717#discussion_r1036063170


##########
arch/sim/src/sim/sim_alsa.c:
##########
@@ -702,6 +836,158 @@ static int sim_mixer_open(struct sim_audio_s *priv)
   return 0;
 }
 
+static signed int sim_audio_mp3_scale(mad_fixed_t sample)
+{
+  sample += (1L << (MAD_F_FRACBITS - 16));
+
+  if (sample >= MAD_F_ONE)
+    sample = MAD_F_ONE - 1;
+  else if (sample < -MAD_F_ONE)
+    sample = -MAD_F_ONE;
+
+  return sample >> (MAD_F_FRACBITS + 1 - 16);
+}
+
+static void *sim_audio_mp3_init()
+{
+  struct sim_decoder_mp3_s *codec;
+
+  codec = malloc(sizeof(struct sim_decoder_mp3_s));
+  if (codec == NULL)
+    {
+      return NULL;
+    }
+
+  mad_stream_init(&codec->stream);
+  mad_frame_init(&codec->frame);
+  mad_synth_init(&codec->synth);
+
+  return codec;
+}
+
+static int sim_audio_mp3_samples(void *handle)
+{
+  struct sim_decoder_mp3_s *codec = (struct sim_decoder_mp3_s *) handle;
+
+  if (codec == NULL)
+    {
+      return -EINVAL;
+    }
+
+  return sizeof(codec->synth.pcm.samples[0]) / sizeof(mad_fixed_t);
+}
+
+static int sim_audio_mp3_decode(void *handle,
+                                unsigned char *in, unsigned int insize,
+                                unsigned char *out, unsigned int *outsize)
+{
+  struct sim_decoder_mp3_s *codec = (struct sim_decoder_mp3_s *) handle;
+  mad_fixed_t const *left_ch, *right_ch;
+  int nchannels;
+  int nsamples;
+  int i = 0;
+  int ret;
+
+  if (codec == NULL || in == NULL || out == NULL || outsize == NULL)

Review Comment:
   done



##########
arch/sim/src/sim/sim_alsa.c:
##########
@@ -702,6 +836,158 @@ static int sim_mixer_open(struct sim_audio_s *priv)
   return 0;
 }
 
+static signed int sim_audio_mp3_scale(mad_fixed_t sample)
+{
+  sample += (1L << (MAD_F_FRACBITS - 16));
+
+  if (sample >= MAD_F_ONE)
+    sample = MAD_F_ONE - 1;
+  else if (sample < -MAD_F_ONE)
+    sample = -MAD_F_ONE;
+
+  return sample >> (MAD_F_FRACBITS + 1 - 16);
+}
+
+static void *sim_audio_mp3_init()
+{
+  struct sim_decoder_mp3_s *codec;
+
+  codec = malloc(sizeof(struct sim_decoder_mp3_s));
+  if (codec == NULL)
+    {
+      return NULL;
+    }
+
+  mad_stream_init(&codec->stream);
+  mad_frame_init(&codec->frame);
+  mad_synth_init(&codec->synth);
+
+  return codec;
+}
+
+static int sim_audio_mp3_samples(void *handle)
+{
+  struct sim_decoder_mp3_s *codec = (struct sim_decoder_mp3_s *) handle;
+
+  if (codec == NULL)

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to