Skip to content

ErnestoLeal/pyWaves

Repository files navigation

Here's an improved README for your Tone Generation project, using the style from your previous AES project:


Tone Generation with Python and a Waveform Generator

Overview

This project, part of a GE-Lab course, focuses on generating tones and waveforms using Python to communicate with a Keysight 33510B Waveform Generator. It includes modular Python scripts for tone generation and music playback, with each function isolated in separate files for clarity and maintainability.

Features

  • Modular Structure: Functions are organized in separate files, enhancing readability and modularity.
  • Waveform Variety: Supports multiple waveform types (sine, square, etc.) for flexible tone generation.
  • Music Playback: Plays musical scales and predefined pieces, including a national anthem.

Project Structure

  • noteDictionary.py: Contains a dictionary mapping musical notes to their frequencies, allowing easy access to notes by name.
  • functionDictionary.py: Defines available waveform functions as dictionary entries, which map keywords to waveform generator commands.
  • playNote.py: Plays a specified note with configurable duration and waveform type, utilizing the dictionaries in noteDictionary and functionDictionary.
  • scale.py: Plays a full musical scale, demonstrating the use of different waveforms on the generator.
  • anthem.py: Plays a national anthem or another specific music piece as defined within the file.
  • setupSource.py: Handles the setup of communication with the waveform generator, including connection, configuration, and resource management.

How It Works

This project leverages Python's PyVISA library to communicate with the waveform generator, allowing the user to generate and play tones with customized waveforms.

  1. Initialize Connection:

    • setupSource.py establishes communication with the waveform generator, ensuring it’s ready for tone generation.
  2. Play a Scale:

    • scale.py uses playNote to play a predefined musical scale, allowing the user to experiment with different waveforms.
  3. Play a National Anthem:

    • anthem.py plays the national anthem or any specific music piece, configured using the notes and waveforms from noteDictionary and functionDictionary.

Requirements

  • Python 3.x

  • Libraries:

    • pyvisa: For communication with the waveform generator
    • time: For delays between note generation

    To install PyVISA, run:

    pip install pyvisa

Usage

Initialize the Waveform Generator Connection

  1. Ensure the waveform generator is connected and powered on.
  2. Run setupSource.py to configure the connection and initialize parameters.

Play a Scale

Run scale.py to play a musical scale using the waveform generator. This file demonstrates various waveforms as defined in functionDictionary.py.

Play a National Anthem

Run anthem.py to play a national anthem or another predefined piece of music on the waveform generator.

Example

Here’s an example of how to play a note using the playNote.py function:

from playNote import play_note

# Parameters: note, duration, speed, waveform
play_note('A4', 1, 100, 'sine')

This command plays the note A4 (440 Hz) for 1 second at 100 BPM, using a sine waveform.

Notes

  • Modular Design: This project follows a modular design, with each function separated into distinct files for clarity and maintainability. Although it does not strictly follow OOP principles, it organizes functionality into reusable, independent components.
  • Improved Code Quality: This implementation uses cleaner, more efficient functions for note and waveform generation, ensuring readability and reusability.

Future Updates

  • Extended Music Library: Additional music pieces and scales for more variety.
  • User Interface: A simple interface allowing users to select notes, set tempo, and choose waveform types.

Let me know if you’d like any further adjustments!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages