Subversion Repositories svn.mios

Rev

Rev 1 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
44 tk 1
// $Id: lfo.c 44 2008-01-30 21:39:30Z tk $
2
/*
3
 * LFO program module
4
 *
5
 * ==========================================================================
6
 *
7
 * Copyright (C) 2005  Thorsten Klose (tk@midibox.org)
8
 *
9
 * ==========================================================================
10
 *
11
 * This file is part of a MIOS application
12
 *
13
 * This application is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This application is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with This application; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 *
27
 * ==========================================================================
28
 */
29
 
30
/////////////////////////////////////////////////////////////////////////////
31
// Include files
32
/////////////////////////////////////////////////////////////////////////////
33
 
34
#include <cmios.h>
35
#include <pic18fregs.h>
36
 
37
#include "main.h"
38
#include "lfo.h"
39
 
40
/////////////////////////////////////////////////////////////////////////////
41
// Global variables
42
/////////////////////////////////////////////////////////////////////////////
43
 
44
// in order to achive best performance, we are NOT using arrays here!
45
 
46
// external accessible variables
47
unsigned int  lfo0_value, lfo1_value;
48
unsigned char lfo0_rate,  lfo1_rate;
49
 
50
// this includes the lfo_add_table
51
// it was generated with: perl utils\lfo_table.pl > lfo_table.inc
52
#include "lfo_table.inc"
53
 
54
 
55
/////////////////////////////////////////////////////////////////////////////
56
// This function initializes the LFO module
57
// it should be called from USER_Init() in main.c
58
/////////////////////////////////////////////////////////////////////////////
59
void LFO_Init(void)
60
{
61
  lfo0_value = lfo0_rate = 0x00;
62
  lfo1_value = lfo1_rate = 0x00;
63
}
64
 
65
 
66
/////////////////////////////////////////////////////////////////////////////
67
// This function is periodically invoked from USER_Timer()
68
/////////////////////////////////////////////////////////////////////////////
69
void LFO_Tick(void)
70
{
71
  // this generates a saw waveform with the given frequency rate
72
  // it can be easily converted to other waveforms by using transforming tables
73
  // (-> see example in map.c, the sinwave[] array)
74
 
75
  if( lfo0_rate > 0 ) {
76
    lfo0_value += lfo_add_table[lfo0_rate];
77
  }
78
 
79
  // note: here you could also add some wired modulations, e.g. lfo0_value controls lfo1_rate
80
 
81
  if( lfo1_rate > 0 ) {
82
    lfo1_value += lfo_add_table[lfo1_rate];
83
  }
84
 
85
}
86