# LaspRS Examples
**WARNING: AI-generated text. Might be inaccurate**
This directory contains examples demonstrating how to use the LaspRS library for acoustic signal processing tasks.
## Available Examples
### 1. `simple_record_analyze.rs`
A minimal example that demonstrates the basic workflow of recording data and analyzing it:
- Records 2 seconds of audio using the system default input device (typically microphone)
- Optionally can use loopback device for testing without audio hardware
- Saves the data to an HDF5 measurement file
- Opens the measurement file and calculates the auto power spectrum of the first channel
- Displays basic statistics and frequency bin information
**Usage:**
```bash
# Using default input device (microphone)
cargo run --example simple_record_analyze --features "record,cpal-api"
# Using loopback device for testing (no microphone required)
cargo run --example simple_record_analyze --features "record,cpal-api,loopback-api"
```
## Key Concepts Demonstrated
### Recording Data
- Setting up a `StreamMgr` for audio I/O management
- Configuring `DaqConfig` for device-specific settings
- Using `RecordSettings` to define recording parameters
- Monitoring recording progress with `RecordStatus`
### Power Spectrum Analysis
- Configuring `CPSSettings` for Cross Power Spectra computation
- Opening measurement files with `Measurement::from_file()`
- Computing auto power spectra using the `CPS()` method
- Working with complex frequency domain data
### File Management
- HDF5-based measurement file format (`.h5` extension)
- Thread-safe access to measurement data using `Arc<RwLock<Measurement>>`
- Proper resource cleanup
## Requirements
To run these examples, you need:
1. **Rust features enabled**: `record` and `cpal-api` (add `loopback-api` for testing without hardware)
2. **Audio device**: The examples will use the default audio input device, or loopback device if enabled
3. **HDF5 libraries**: Required for measurement file I/O
## Notes
- By default, the examples use the system default input device (typically microphone)
- The loopback device can be used for testing without audio hardware by enabling the `loopback-api` feature
- Measurement files are automatically cleaned up after analysis
- The examples demonstrate both simple and advanced usage patterns
- Error handling shows proper practices for robust applications
## Extending the Examples
These examples serve as starting points for more complex applications. You can extend them by:
- Adding signal generation capabilities
- Implementing real-time analysis
- Working with multiple channels simultaneously
- Applying different frequency weightings (A, C, Z)
- Using different window functions and overlap settings
- Integrating with external hardware devices