SoundFont.fromBinaryReader constructor

SoundFont.fromBinaryReader(
  1. BinaryReader reader
)

Implementation

factory SoundFont.fromBinaryReader(BinaryReader reader) {

  String chunkId = reader.readFourCC();
  if (chunkId != "RIFF") {
    throw "The RIFF chunk was not found.";
  }

  // ignore: unused_local_variable
  int size = reader.readInt32();

  String formType = reader.readFourCC();
  if (formType != "sfbk") {
    throw "The type of the RIFF chunk must be 'sfbk', but was '$formType'.";
  }

  var info = SoundFontInfo.fromReader(reader);
  var sampleData = SoundFontSampleData.fromReader(reader);
  var parameters = SoundFontParameters.fromReader(reader);

  SoundFont sf = SoundFont(
    info: info,
    bitsPerSample: sampleData.bitsPerSample,
    waveData: sampleData.samples,
    sampleHeaders: parameters.sampleHeaders,
    presets: parameters.presets,
    instruments: parameters.instruments,
  );

  sf._checkSamples();
  sf._checkRegions();

  return sf;
}