Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Spencer Alves via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Spencer Alves <impiaaa@gmail.com>
Subject: [FFmpeg-devel] [PATCH] avformat/wavdec: support loop_start and loop_end from 'smpl' chunk
Date: Sat, 30 Aug 2025 16:27:25 -0700
Message-ID: <4ac2a014-38fc-4ba4-8ea4-73ea281c3d1b@gmail.com> (raw)

The 'smpl' chunk is used for sampling music synthesizers, and includes 
things like the pitch of the sample and how to loop it. This exposes the 
loop points as "loop_start" and "loop_end" metadata, that the brstm, 
mca, and scd demuxers already support.

Tested with file output from "Polyphone" soundfont editor.

Signed-off-by: Spencer Alves <impiaaa@gmail.com>
---
  libavformat/wavdec.c | 22 ++++++++++++++++++++++
  1 file changed, 22 insertions(+)

diff --git a/libavformat/wavdec.c b/libavformat/wavdec.c
index c65e0a2723..fb3749d64d 100644
--- a/libavformat/wavdec.c
+++ b/libavformat/wavdec.c
@@ -595,6 +595,28 @@ static int wav_read_header(AVFormatContext *s)
                  }
              }
              break;
+        case MKTAG('s', 'm', 'p', 'l'):
+            if (size >= 36 && got_fmt && st->codecpar->sample_rate > 0) {
+                unsigned sample_loop_count;
+                avio_skip(pb, 28);
+                sample_loop_count = avio_rl32(pb);
+                avio_skip(pb, 4);
+                for (unsigned i = 0; i < sample_loop_count; i++) {
+                    avio_skip(pb, 8);
+                    if (av_dict_set_int(&s->metadata, "loop_start",
+                            av_rescale(avio_rl32(pb), AV_TIME_BASE,
+                                       st->codecpar->sample_rate),
+                            AV_DICT_MULTIKEY) < 0)
+                        return AVERROR(ENOMEM);
+                    avio_skip(pb, 8);
+                    if (av_dict_set_int(&s->metadata, "loop_end",
+                            av_rescale(avio_rl32(pb), AV_TIME_BASE,
+                                       st->codecpar->sample_rate),
+                            AV_DICT_MULTIKEY) < 0)
+                        return AVERROR(ENOMEM);
+                }
+            }
+            break;
          }
           /* seek to next tag unless we know that we'll run into EOF */
-- 
2.48.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-08-30 23:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ac2a014-38fc-4ba4-8ea4-73ea281c3d1b@gmail.com \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=impiaaa@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git