Song Class |
The Song type exposes the following members.
Name | Description | |
---|---|---|
Song | Creates a new song with a 3/4 measure size, a tempo of 240 quarter-notes per minute, mezzo-forte prevailing dynamic level, using a basic note timbre and standard CD-quality settings for the underlying sound file. | |
Song(SampleRate, BitsPerSample, DataChannels) | Creates a new song with a 3/4 measure size, a tempo of 240 quarter-notes per minute, mezzo-forte prevailing dynamic level, using a basic note timbre and the specified audio format settings. |
Name | Description | |
---|---|---|
AmplitudeScalar |
Returns the amplitude scalar for the given bits per sample of the WaveFile (i.e., maximum value
for given BitsPerSample).
(Inherited from WaveFile) | |
AudioFormat |
Gets or sets audio format used by the WaveFile.
(Inherited from WaveFile) | |
AudioLength |
Gets calculated audio length.
(Inherited from WaveFile) | |
BeatTime | Returns the time for a single beat. | |
BitsPerSample |
Gets or sets number of bits-per-sample in the WaveFile.
(Inherited from WaveFile) | |
BlockAlignment |
Gets or sets the block size of a complete sample of data (i.e., samples for all channels of data at
one instant in time).
(Inherited from WaveFile) | |
ByteRate |
Gets or sets the byte rate used for buffer estimation.
(Inherited from WaveFile) | |
Channels |
Gets or sets number of audio channels in the WaveFile.
(Inherited from WaveFile) | |
Damping | Gets or sets the default damping function used to lower the sound volume of the added notes over time. This damping function will be used if no other function is specified when adding notes. | |
DataChunk |
Gets or sets the WaveDataChunk of this WaveFile.
(Inherited from WaveFile) | |
Dynamic | Gets or sets the prevailing dynamic (i.e., volume) expressed as percentage in the range of 0 to 1 for the song. Individual notes can choose to override this dynamic. | |
ExtraParameters |
Gets or sets any extra parameters defined in the format header of the WaveFile.
(Inherited from WaveFile) | |
ExtraParametersSize |
Gets the size of the ExtraParameters buffer, if defined.
(Inherited from WaveFile) | |
FormatChunk |
Gets or sets the WaveFormatChunk of this WaveFile.
(Inherited from WaveFile) | |
HeaderChunk |
Gets or sets the RiffHeaderChunk of this WaveFile.
(Inherited from WaveFile) | |
InfoChunk |
Gets the ListInfoChunk of this WaveFile.
(Inherited from WaveFile) | |
InfoStrings |
Gets list of info strings available in this WaveFile if any were available during load; otherwise an empty dictionary.
(Inherited from WaveFile) | |
InterNoteDelay | Injects specified rest time, in seconds, between notes. | |
MeasureSize | Gets current measure size or defines a new measure size for the song. | |
NamedDynamic | Gets or sets the prevailing named dynamic (i.e., volume) for the song. Individual notes can choose to override this dynamic. | |
SampleBlocks |
Accesses each individual block of sample data indexed by time.
(Inherited from WaveFile) | |
SampleRate |
Gets or sets the sample rate (i.e., the number of samples per second) defined in the WaveFile.
(Inherited from WaveFile) | |
Tempo | Gets current tempo or defines a new tempo for the song. | |
Timbre | Gets or sets the default tibre function used to synthesize the sounds of the added notes (i.e., the instrument). This timbre function will be used if no other function is specified when adding notes. |
Name | Description | |
---|---|---|
AddNotes | Add a series of notes to the song. | |
AddPhrase | Add a predefined phrase of notes to the song. | |
AddRest(Double) | Add a rest for the given length for the current beat. | |
AddRest(NoteValue) | Add a rest for the given length for the current beat. | |
AddRest(NoteValueBritish) | Add a rest for the given length for the current beat. | |
AddRest(NoteValue, Int32) | Add a rest for the given length for the current beat. | |
AddRest(NoteValueBritish, Int32) | Add a rest for the given length for the current beat. | |
AddSample |
Add the sample to the wave file.
(Inherited from WaveFile) | |
AddSampleBlock |
Adds a block of samples in native format to the wave file (e.g., if BitsPerSample = 16,
parameters need to be Int16 values). Note that LittleBinaryValue parameter type is
implicitly castable to common native types, including floating points.
(Inherited from WaveFile) | |
AddSamples |
Adds a series of samples, one per channel, to the wave file.
(Inherited from WaveFile) | |
CastSample |
Casts sample value to its equivalent native type based on defined BitsPerSample
and AudioFormat.
(Inherited from WaveFile) | |
Clone |
Creates a deeply cloned copy of the WaveFile.
(Inherited from WaveFile) | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) | |
Finish | Called when there are no more notes to add. | |
GetHashCode | Serves as the default hash function. (Inherited from Object) | |
GetSampleTypeCode |
Determines sample data type code based on defined BitsPerSample
and AudioFormat.
(Inherited from WaveFile) | |
GetType | Gets the Type of the current instance. (Inherited from Object) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
Play |
Plays the wave file using SoundPlayer.
(Inherited from WaveFile) | |
Reverse |
Reverses the data samples in the wave file.
(Inherited from WaveFile) | |
Save(Stream) |
Saves wave file to the specified stream.
(Inherited from WaveFile) | |
Save(String) |
Saves wave file to the specified file name.
(Inherited from WaveFile) | |
SetCrescendoDynamic | Starts crescendo dynamic over the range of the specified number of beats. | |
SetDiminuendoDynamic | Starts diminuendo dynamic over the range of the specified number of beats. | |
ToString | Returns a string that represents the current object. (Inherited from Object) |
Name | Description | |
---|---|---|
GetEnumValueOrDefault |
Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) | |
GetEnumValueOrDefaultT |
Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) |
using System; using GSF.Media; using GSF.Media.Music; static class Program { static void Main() { Song song = new Song { Damping = Damping.Linear }; Console.WriteLine("Generating multi-instrument chord..."); song.AddNotes ( new Note { Frequency = Note.C4, Value = 4, Timbre = Timbre.EvenHarmonicSeries }, new Note { Frequency = Note.C4, Value = 4, Timbre = Timbre.Clarinet }, new Note { Frequency = Note.C4, Value = 4, Timbre = Timbre.Organ }, new Note { Frequency = Note.E4, Value = 4, Timbre = Timbre.EvenHarmonicSeries }, new Note { Frequency = Note.E4, Value = 4, Timbre = Timbre.Clarinet }, new Note { Frequency = Note.E4, Value = 4, Timbre = Timbre.Organ }, new Note { Frequency = Note.G4, Value = 4, Timbre = Timbre.EvenHarmonicSeries }, new Note { Frequency = Note.G4, Value = 4, Timbre = Timbre.SimulatedClarinet }, new Note { Frequency = Note.G4, Value = 4, Timbre = Timbre.SimulatedOrgan } ); song.Finish(); Console.WriteLine("Saving chord to disk..."); song.Save("MajorTriad.wav"); Console.WriteLine("Playing chord..."); song.Play(); Console.ReadKey(); } }
// Add reference to System.Speech using System; using System.IO; using GSF.Media; using GSF.Media.Music; using System.Speech; using System.Speech.Synthesis; using System.Speech.AudioFormat; static class Program { static void Main() { Console.WriteLine("Synthesizing speech..."); WaveFile speech = CreateSynthesizedVoiceOver(); Console.WriteLine("Synthesizing song at tempo for use with speech..."); // Define all the notes of jingle bells as a single phrase of music Phrase score = CreateJingleBellsScore(); // Create one song at a slower tempo to help with speech synchronization Song speechTempSong = new Song { Tempo = new Tempo(160, NoteValue.Quarter) }; // Make sure audio specifications for song and speech match speechTempSong.SampleRate = speech.SampleRate; speechTempSong.BitsPerSample = speech.BitsPerSample; speechTempSong.Channels = speech.Channels; // Add all the notes to the song speechTempSong.AddPhrase(score); speechTempSong.Finish(); Console.WriteLine("Synthesizing song by itself at normal tempo..."); // Create one song at a slower tempo to help with speech synchronization Song normalTempoSong = new Song(); // Add all the notes to the song normalTempoSong.AddPhrase(score); normalTempoSong.Finish(); Console.WriteLine("Saving normal tempo song to disk as \"JingleBells.wav\"..."); normalTempoSong.Save("JingleBells.wav"); Console.WriteLine("Combining speech with song..."); WaveFile combined = WaveFile.Combine(speech, speechTempSong); Console.WriteLine("Saving combined work to disk as \"SingingComputer.wav\"..."); combined.Save("SingingComputer.wav"); Console.WriteLine("Playing combined work..."); combined.Play(); Console.ReadKey(); } private static WaveFile CreateSynthesizedVoiceOver() { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); MemoryStream speechStream = new MemoryStream(); PromptBuilder songText = new PromptBuilder(); synthesizer.SelectVoice("Microsoft Sam"); synthesizer.Rate = 5; // Range = -10 to +10 synthesizer.SetOutputToWaveStream(speechStream); songText.AppendText("Jin - gull bells!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(3000000)); songText.AppendText("Jin - gull bells!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(3000000)); songText.AppendText("Jin - gull - all, theuh - way!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(12000000)); songText.AppendText("Oh - what - fun!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(1000000)); songText.AppendText("It - is!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("To - ride!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("a - one - horse!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("Open!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("Sleigh!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(1000000)); songText.AppendText("A!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(2500000)); songText.AppendText("Jin - gull bells!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(3000000)); songText.AppendText("Jin - gull bells!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(3000000)); songText.AppendText("Jin - gull - all, theuh - way!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(12000000)); songText.AppendText("Oh - what - fun!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(1000000)); songText.AppendText("It - is!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("To - ride!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("a - one - horse!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("Open!", PromptEmphasis.Strong); songText.AppendBreak(new TimeSpan(500000)); songText.AppendText("Sleigh.", PromptEmphasis.Reduced); synthesizer.Speak(songText); speechStream.Position = 0; return WaveFile.Load(speechStream); } private static Phrase CreateJingleBellsScore() { Phrase score = new Phrase(); Phrase passage = new Phrase(); // Define the repeating phrase of the song passage.AddNotes ( new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }, new Note { Frequency = Note.C3, NamedValue = NoteValue.Whole } ); passage.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Half }); passage.AddNotes ( new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }, new Note { Frequency = Note.G3, NamedValue = NoteValue.Whole } ); passage.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Half }); passage.AddNotes ( new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }, new Note { Frequency = Note.C3, NamedValue = NoteValue.Whole } ); passage.AddNotes(new Note { Frequency = Note.D4, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.G3, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.A3, NamedValue = NoteValue.Quarter }); passage.AddNotes ( new Note { Frequency = Note.B3, NamedValue = NoteValue.Whole }, new Note { Frequency = Note.G3, NamedValue = NoteValue.Whole } ); passage.AddNotes ( new Note { Frequency = Note.C4, NamedValue = NoteValue.Quarter }, new Note { Frequency = Note.D3, NamedValue = NoteValue.Whole } ); passage.AddNotes(new Note { Frequency = Note.C4, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.C4, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.C4, NamedValue = NoteValue.Quarter }); passage.AddNotes ( new Note { Frequency = Note.C4, NamedValue = NoteValue.Quarter }, new Note { Frequency = Note.G3, NamedValue = NoteValue.Whole } ); passage.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }); passage.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }); score.AddPhrase(passage); score.AddNotes ( new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }, new Note { Frequency = Note.F3S, NamedValue = NoteValue.Whole } ); score.AddNotes(new Note { Frequency = Note.A3, NamedValue = NoteValue.Quarter }); score.AddNotes(new Note { Frequency = Note.A3, NamedValue = NoteValue.Quarter }); score.AddNotes(new Note { Frequency = Note.B3, NamedValue = NoteValue.Quarter }); score.AddNotes ( new Note { Frequency = Note.A3, NamedValue = NoteValue.Half }, new Note { Frequency = Note.G3, NamedValue = NoteValue.Whole } ); score.AddNotes(new Note { Frequency = Note.D4, NamedValue = NoteValue.Half }); score.AddPhrase(passage); score.AddNotes ( new Note { Frequency = Note.D4, NamedValue = NoteValue.Quarter }, new Note { Frequency = Note.G3, NamedValue = NoteValue.Whole }, new Note { Frequency = Note.F3, NamedValue = NoteValue.Whole } ); score.AddNotes(new Note { Frequency = Note.D4, NamedValue = NoteValue.Quarter }); score.AddNotes(new Note { Frequency = Note.C4, NamedValue = NoteValue.Quarter }); score.AddNotes(new Note { Frequency = Note.A3, NamedValue = NoteValue.Quarter }); score.AddNotes ( new Note { Frequency = Note.G3, NamedValue = NoteValue.Whole }, new Note { Frequency = Note.E3, NamedValue = NoteValue.Whole } ); return score; } }