Code Monkey home page Code Monkey logo

cple-metronome's Introduction

Cple Metronome

Description

Example

This program is a simple metronome. Users can define beats per minute, beats per measure, and the upbeat/downbeat sound from the command line first.

Beats per minute(BPM) is a term used to describe the tempo. Beats per measure is another term, meaning the number of beats in every β€œloop”. The downbeat is commonly the first beat in each measure. The upbeat sound is the one that sounds lighter. For example, if a user sets beats per measure as three, then there will be a loop with one time downbeat and two times upbeat. The metronome is a very useful tool and can be used in music instrument practicing.

The range of beats per minute is [30, 280], while the range of beats per measure is [2,12]. If the input value is not in this range, the program will show an error with the corresponding information. The downbeat and upbeat sound should be short enough in order to play properly. If the number of samples in each sound file is larger than the number of samples in each beat, there will be error information.

The upbeat and downbeat sound can be defined by the user by editing the ifile_list.txt and signal menu. In this file, users can define two .wav files, which are written in the format of ./signals/filename.txt. Also, users need to put the chosen file under the signal menu.

buffer

The samples in each loop are arranged by calculating samples in each beat and each loop based on user input. The graph above shows the process. In each beat, we put the beat sound in the first half and set the magnitude of the other half as zero. In addition, we decide whether the sound played is downbeat or upbeat by determining whether it is the first beat of each loop.

π‘“π‘Ÿπ‘Žπ‘šπ‘’π‘ƒπ‘’π‘Ÿπ΅π‘’π‘Žπ‘‘ = 60 * π‘ π‘Žπ‘šπ‘π‘™π‘’π‘…π‘Žπ‘‘π‘’ / π‘π‘’π‘Žπ‘‘π‘ π‘ƒπ‘’π‘Ÿπ‘€π‘–π‘›π‘’π‘‘π‘’

π‘“π‘Ÿπ‘Žπ‘šπ‘’π‘ƒπ‘’π‘ŸπΏπ‘œπ‘œπ‘ = π‘“π‘Ÿπ‘Žπ‘šπ‘’π‘ƒπ‘’π‘Ÿπ΅π‘’π‘Žπ‘‘ * π‘π‘’π‘Žπ‘‘π‘ π‘ƒπ‘’π‘Ÿπ‘€π‘’π‘Žπ‘ π‘’π‘Ÿπ‘’

π‘ π‘Žπ‘šπ‘π‘™π‘’π‘ π‘ƒπ‘’π‘Ÿπ΅π‘’π‘Žπ‘‘ = π‘“π‘Ÿπ‘Žπ‘šπ‘’π‘ƒπ‘’π‘Ÿπ΅π‘’π‘Žπ‘‘ * π‘β„Žπ‘Žπ‘›π‘›π‘’π‘™π‘ 

We can use the equations bove to calculate frames per beat, frames per loop and samples per beat.

Signal Flow

flow

In metronome.c:

  • main()
    • Parses the command line
    • Check if the input value is within the range
    • Read the audio data from each file into its own buffer
    • Calculate frame per beat and frame per loop from input data
    • Allocate memory according to the length of the block (β€œloop”)
    • Free the memory space
  • user_input()
    • Display essential information
    • User control play/stop/quit
  • paCallback()
    • Reads a block of audio from the input file.
    • Construct the output block (β€œloop”) according to the user input
    • Put the upbeat and downbeat sound into the block at the corresponding place
    • Output the constructed loop

Libraries

  • Sndfile
  • Portaudio

These libraries were obtained from brew:

Brew install sndfile
Brew install portlib

Compilation and Linking

Build.sh can be directly used to compile and link the program on the OS X platform. Or we can also use the following command line to compile:

gcc -Wall -o metronome metronome.c paUtils.c \

Command Line

We can use the following command line format to run the program:

./metronome ifile.txt beatsPerMinute beatsPerMeasure inputfile.wav

Here are some examples:

./metronome ifile_list.txt 120 3
./metronome ifile_list.txt 180 5

The ifile_list.txt should be like:

./signals/sig1.wav
./signals/sig2.wav

cple-metronome's People

Contributors

shanyi15 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.