【问题标题】:Libsndfile - How do deal with extra chunks (metadata)Libsndfile - 如何处理额外的块(元数据)
【发布时间】:2015-06-08 11:30:59
【问题描述】:

我正在使用 libsndfile(带有 c# 包装器)基于现有的 wav 文件创建 wav/aiff 文件,例如将立体声文件转换为单声道文件,反之亦然。

我的流程是:

  1. 读取现有文件
  2. 在填充 LibsndfileInfo 时打开新文件进行写入
  3. 将项目写入新文件

                LibsndfileInfo fInfo = new LibsndfileInfo();
                fInfo.Format = info.Format;
                fInfo.Channels = info.Channels;
                fInfo.SampleRate = info.SampleRate;              
    
                IntPtr sndOutFile = api.Open(outfilename, LibsndfileMode.Write, ref fInfo);
    
                api.WriteItems(sndOutFile, data, num_items);
    
                api.Close(sndOutFile);
    

在执行此操作时,我注意到原始文件中的任何额外元数据(额外块)都会在结果文件中丢失。

有没有办法以某种方式带来这些额外的块或使用 libsndfile 将标头复制到新文件?

感谢您的任何意见。

迈克

【问题讨论】:

  • 只是想看看这个,看看是否有人对此有任何意见。非常感谢。

标签: c# metadata chunks libsndfile


【解决方案1】:

我不知道 C# 包装器,但 libsndfile C 和 C++ api 具有 command 函数,允许读取和写入块中包含的信息,如广播信息和其他字符串:

// Open input file
SndfileHandle inputFile(inputFileName, SFM_READ);

// Read broadcast info:
SF_BROADCAST_INFO binfo;
file.command(SFC_GET_BROADCAST_INFO, &binfo, sizeof (binfo));

std::cout() << binfo.description;

// Open output file with same parameters:
SndfileHanle outputFile(outputFileName, SFM_WRITE, inputFile.format(), inputFile.channels(), inputFile.samplerate());

// Copy broadcast info:
outputFile.command(SFC_SET_BROADCAST_INFO, &binfo, sizeof (binfo));

// Copy other string info:
outputFile.setString(SF_STR_TITLE, inputFile.getString(SF_STR_TITLE));
outputFile.setString(SF_STR_COPYRIGHT, inputFile.getString(SF_STR_COPYRIGHT));
outputFile.setString(SF_STR_SOFTWARE, inputFile.getString(SF_STR_SOFTWARE));
outputFile.setString(SF_STR_ARTIST, inputFile.getString(SF_STR_ARTIST));
outputFile.setString(SF_STR_COMMENT, inputFile.getString(SF_STR_COMMENT));
outputFile.setString(SF_STR_DATE, inputFile.getString(SF_STR_DATE));
outputFile.setString(SF_STR_ALBUM, inputFile.getString(SF_STR_ALBUM));
outputFile.setString(SF_STR_LICENSE, inputFile.getString(SF_STR_LICENSE));
outputFile.setString(SF_STR_TRACKNUMBER, inputFile.getString(SF_STR_TRACKNUMBER));
outputFile.setString(SF_STR_GENRE, inputFile.getString(SF_STR_GENRE));

// Copy sound data:
....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 2021-07-19
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    相关资源
    最近更新 更多