Skip to content

Commit

Permalink
fix #124656: mtests for Zerberus
Browse files Browse the repository at this point in the history
  • Loading branch information
hpfmn committed Sep 16, 2016
1 parent f136458 commit 04e80fb
Show file tree
Hide file tree
Showing 30 changed files with 1,069 additions and 0 deletions.
7 changes: 7 additions & 0 deletions mtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ subdirs (
guitarpro
scripting
testoves
zerberus/comments
zerberus/envelopes
zerberus/includes
zerberus/global
zerberus/opcodeparse
zerberus/inputControls
zerberus/loop
)


Expand Down
Binary file added mtest/zerberus/10Zeros50Ones50Zeros.wav
Binary file not shown.
Binary file added mtest/zerberus/Ones.wav
Binary file not shown.
22 changes: 22 additions & 0 deletions mtest/zerberus/comments/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
# $Id:$
#
# Copyright (C) 2011 Werner Schweer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation and appearing in
# the file LICENSE.GPL
#=============================================================================

set(TARGET tst_sfzcomments)

include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc)

include_directories(
${SNDFILE_INCDIR}
)

target_link_libraries(tst_sfzcomments zerberus synthesizer audiofile ${SNDFILE_LIB})
13 changes: 13 additions & 0 deletions mtest/zerberus/comments/commentTest.sfz
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<group>
sample=../sample.wav
pitch_keycenter=40
// <region> line comment
//<region> line comment with spaces at the beginning
<region> lokey=60 hikey=70 // <region> line comment with opcodes at the beginning
<region> lokey=23 /* lokey=45 */ hikey=42 /* hikey=58*/ // block in line
/* block multiline
<region>
<region>
*/ <region> lokey=42 /* new block after block */ hikey=23 /*
<region> some more
*/
76 changes: 76 additions & 0 deletions mtest/zerberus/comments/tst_sfzcomments.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

//=============================================================================
// MuseScore
// Music Composition & Notation
// $Id:$
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#include <QtTest/QtTest>

#include "mtest/testutils.h"

#include "zerberus/instrument.h"
#include "zerberus/zerberus.h"
#include "zerberus/zone.h"
#include "mscore/preferences.h"

using namespace Ms;

//---------------------------------------------------------
// TestSfzComments
//---------------------------------------------------------

class TestSfzComments : public QObject, public MTest
{
Q_OBJECT

private slots:
void initTestCase();
void testcomments();
};

//---------------------------------------------------------
// initTestCase
//---------------------------------------------------------

void TestSfzComments::initTestCase()
{
initMTest();
}

//---------------------------------------------------------
// testcomments
//---------------------------------------------------------

void TestSfzComments::testcomments()
{
Zerberus* synth = new Zerberus();
Ms::preferences.mySoundfontsPath += ";" + root;
synth->loadInstrument("commentTest.sfz");

QCOMPARE(synth->instrument(0)->zones().size(), (unsigned long) 3);

std::list<Zone *>::iterator curZone = synth->instrument(0)->zones().begin();
QCOMPARE((*curZone)->keyLo, (char) 60);
QCOMPARE((*curZone)->keyHi, (char) 70);
QCOMPARE((*curZone)->keyBase, (char) 40);
curZone++;
QCOMPARE((*curZone)->keyLo, (char) 23);
QCOMPARE((*curZone)->keyHi, (char) 42);
QCOMPARE((*curZone)->keyBase, (char) 40);
curZone++;
QCOMPARE((*curZone)->keyLo, (char) 42);
QCOMPARE((*curZone)->keyHi, (char) 23);
QCOMPARE((*curZone)->keyBase, (char) 40);
}

QTEST_MAIN(TestSfzComments)

#include "tst_sfzcomments.moc"


22 changes: 22 additions & 0 deletions mtest/zerberus/envelopes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
# $Id:$
#
# Copyright (C) 2011 Werner Schweer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation and appearing in
# the file LICENSE.GPL
#=============================================================================

set(TARGET tst_sfzenvelopes)

include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc)

include_directories(
${SNDFILE_INCDIR}
)

target_link_libraries(tst_sfzenvelopes zerberus synthesizer audiofile ${SNDFILE_LIB})
8 changes: 8 additions & 0 deletions mtest/zerberus/envelopes/envelopesTest.sfz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<global>
sample=../Ones.wav// a file containing 200 Samples with Value 1.0
volume=0
<group>
loop_mode=loop_continuous
loop_start=50
loop_end=150
<region> ampeg_delay=0.01 ampeg_start=20 ampeg_attack=0.01 ampeg_hold=0.01 ampeg_decay=0.01 ampeg_sustain=50 ampeg_release=0.01
Binary file added mtest/zerberus/envelopes/result.wav
Binary file not shown.
115 changes: 115 additions & 0 deletions mtest/zerberus/envelopes/tst_sfzenvelopes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

//=============================================================================
// MuseScore
// Music Composition & Notation
// $Id:$
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#include <QtTest/QtTest>

#include "mtest/testutils.h"

#include "zerberus/instrument.h"
#include "zerberus/zerberus.h"
#include "zerberus/zone.h"
#include "mscore/preferences.h"
#include "synthesizer/event.h"
#include <sndfile.h>

using namespace Ms;

//---------------------------------------------------------
// TestSfzEnvelopes
//---------------------------------------------------------

class TestSfzEnvelopes : public QObject, public MTest
{
Q_OBJECT
float samplerate = 44100;
Zerberus* synth;

private slots:
void initTestCase();
void testEnvelopesParsing();
void testEnvelopesAudio();
public:
~TestSfzEnvelopes();
};

//---------------------------------------------------------
// initTestCase
//---------------------------------------------------------

void TestSfzEnvelopes::initTestCase()
{
initMTest();
synth = new Zerberus();
synth->init(samplerate);
Ms::preferences.mySoundfontsPath += ";" + root;
synth->loadInstrument("envelopesTest.sfz");
}

//---------------------------------------------------------
// testglobal
//---------------------------------------------------------

void TestSfzEnvelopes::testEnvelopesParsing()
{
QCOMPARE(synth->instrument(0)->zones().size(), (unsigned long) 1);
QCOMPARE(synth->instrument(0)->zones().front()->ampegDelay, 0.01f * 1000.0f);
QCOMPARE(synth->instrument(0)->zones().front()->ampegStart, 20.0f / 100.0f); // 20 percent
QCOMPARE(synth->instrument(0)->zones().front()->ampegAttack, 0.01f * 1000.0f);
QCOMPARE(synth->instrument(0)->zones().front()->ampegHold, 0.01f * 1000.0f);
QCOMPARE(synth->instrument(0)->zones().front()->ampegDecay, 0.01f * 1000.0f);
QCOMPARE(synth->instrument(0)->zones().front()->ampegSustain, 50.0f / 100.0f); // 50 percent
QCOMPARE(synth->instrument(0)->zones().front()->ampegRelease, 0.01f * 1000.0f);
}

void TestSfzEnvelopes::testEnvelopesAudio()
{
synth->play(Ms::PlayEvent(ME_PROGRAM, 0, 0, 0));
float data[6 * 441 * 2]; // 6 envelope stages with duration of 441 Samples and 2 Channels
memset(data, 0, sizeof(data));
synth->play(Ms::PlayEvent(ME_NOTEON, 0, 60, 127)); // play a note
synth->process(5*441 , data, nullptr, nullptr); // process until end of sustain stage
synth->play(Ms::PlayEvent(ME_NOTEON, 0, 60, 0)); // send note off
synth->process(441 , data + (5*441*2), nullptr, nullptr); // process until end of sustain stage

/* To generate wav file
SF_INFO sf_info;
sf_info.channels = 2;
sf_info.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
sf_info.frames = 6 *441;
sf_info.samplerate = samplerate;
SNDFILE* sf = sf_open("result.wav", SFM_WRITE, &sf_info);
sf_writef_float(sf, data, 441*6);
sf_close(sf); */

// read wav file
QString filename = root + "/zerberus/envelopes/result.wav";
SF_INFO sf_info;
SNDFILE *sf = sf_open(filename.toLocal8Bit().constData(), SFM_READ, &sf_info);
float compare_data[6 * 441 * 2];
sf_readf_float(sf, compare_data, 6 * 441);
sf_close(sf);

for (int i = 0; i < 6 * 441 * 2; i++)
QCOMPARE(data[i], compare_data[i]);

}

TestSfzEnvelopes::~TestSfzEnvelopes()
{
delete synth;
}

QTEST_MAIN(TestSfzEnvelopes)

#include "tst_sfzenvelopes.moc"


22 changes: 22 additions & 0 deletions mtest/zerberus/global/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
# $Id:$
#
# Copyright (C) 2011 Werner Schweer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation and appearing in
# the file LICENSE.GPL
#=============================================================================

set(TARGET tst_sfzglobal)

include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc)

include_directories(
${SNDFILE_INCDIR}
)

target_link_libraries(tst_sfzglobal zerberus synthesizer audiofile ${SNDFILE_LIB})
8 changes: 8 additions & 0 deletions mtest/zerberus/global/globalTest.sfz
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<global>
sample=../sample.wav
<group>
lokey=40
hikey=50
pitch_keycenter=40
<region>
<region> lokey=60 hikey=70
68 changes: 68 additions & 0 deletions mtest/zerberus/global/tst_sfzglobal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

//=============================================================================
// MuseScore
// Music Composition & Notation
// $Id:$
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#include <QtTest/QtTest>

#include "mtest/testutils.h"

#include "zerberus/instrument.h"
#include "zerberus/zerberus.h"
#include "zerberus/zone.h"
#include "mscore/preferences.h"

using namespace Ms;

//---------------------------------------------------------
// TestSfzGlobal
//---------------------------------------------------------

class TestSfzGlobal : public QObject, public MTest
{
Q_OBJECT

private slots:
void initTestCase();
void testglobal();
};

//---------------------------------------------------------
// initTestCase
//---------------------------------------------------------

void TestSfzGlobal::initTestCase()
{
initMTest();
}

//---------------------------------------------------------
// testglobal
//---------------------------------------------------------

void TestSfzGlobal::testglobal()
{
Zerberus* synth = new Zerberus();
Ms::preferences.mySoundfontsPath += ";" + root;
synth->loadInstrument("globalTest.sfz");
QCOMPARE(synth->instrument(0)->zones().size(), (unsigned long) 2);
QCOMPARE(synth->instrument(0)->zones().front()->keyLo, (char) 40);
QCOMPARE(synth->instrument(0)->zones().front()->keyHi, (char) 50);
QCOMPARE(synth->instrument(0)->zones().front()->keyBase, (char) 40);
QCOMPARE(synth->instrument(0)->zones().back()->keyLo, (char) 60);
QCOMPARE(synth->instrument(0)->zones().back()->keyHi, (char) 70);
QCOMPARE(synth->instrument(0)->zones().back()->keyBase, (char) 40);
}

QTEST_MAIN(TestSfzGlobal)

#include "tst_sfzglobal.moc"


22 changes: 22 additions & 0 deletions mtest/zerberus/includes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
# $Id:$
#
# Copyright (C) 2011 Werner Schweer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation and appearing in
# the file LICENSE.GPL
#=============================================================================

set(TARGET tst_sfzincludes)

include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc)

include_directories(
${SNDFILE_INCDIR}
)

target_link_libraries(tst_sfzincludes zerberus synthesizer audiofile ${SNDFILE_LIB})
Loading

0 comments on commit 04e80fb

Please sign in to comment.