2011-02-23 10:52:22 +00:00
/*
2009-08-28 21:31:13 +00:00
* $ Id $
2009-08-28 11:13:45 +00:00
*
* * * * * * BEGIN GPL LICENSE BLOCK * * * * *
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software Foundation ,
2010-02-12 13:34:04 +00:00
* Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2009-08-28 11:13:45 +00:00
*
* The Original Code is Copyright ( C ) 2007 Blender Foundation .
* All rights reserved .
*
*
* Contributor ( s ) : Blender Foundation
*
* * * * * * END GPL LICENSE BLOCK * * * * *
*/
2011-02-27 20:29:51 +00:00
/** \file blender/editors/sound/sound_ops.c
* \ ingroup edsnd
*/
2009-08-28 21:47:05 +00:00
# include <string.h>
# include <stdlib.h>
2009-08-28 11:13:45 +00:00
# include <stdio.h>
2011-01-26 14:18:16 +00:00
# include <stddef.h>
2009-08-28 11:13:45 +00:00
2010-05-29 21:31:57 +00:00
# include "MEM_guardedalloc.h"
2011-01-07 18:36:47 +00:00
# include "BLI_blenlib.h"
# include "BLI_utildefines.h"
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
# include "DNA_anim_types.h"
2009-08-28 21:47:05 +00:00
# include "DNA_packedFile_types.h"
2009-08-28 11:13:45 +00:00
# include "DNA_scene_types.h"
# include "DNA_space_types.h"
2009-08-28 21:47:05 +00:00
# include "DNA_sequence_types.h"
2010-08-04 04:01:27 +00:00
# include "DNA_sound_types.h"
2010-05-29 21:31:57 +00:00
# include "DNA_userdef_types.h"
2009-08-28 11:13:45 +00:00
# include "BKE_context.h"
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
# include "BKE_fcurve.h"
2009-08-28 21:47:05 +00:00
# include "BKE_global.h"
2011-01-26 14:18:16 +00:00
# include "BKE_main.h"
2009-08-28 11:13:45 +00:00
# include "BKE_report.h"
2009-08-28 21:47:05 +00:00
# include "BKE_packedFile.h"
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
# include "BKE_scene.h"
2009-08-28 11:13:45 +00:00
# include "BKE_sound.h"
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
# include "BKE_sequencer.h"
2009-08-28 11:13:45 +00:00
# include "RNA_access.h"
# include "RNA_define.h"
2009-08-28 21:47:05 +00:00
# include "RNA_enum_types.h"
# include "UI_interface.h"
2009-08-28 11:13:45 +00:00
# include "WM_api.h"
# include "WM_types.h"
2011-06-23 09:27:56 +00:00
# ifdef WITH_AUDASPACE
# include "AUD_C-API.h"
# endif
2009-08-28 11:13:45 +00:00
2011-02-14 17:55:27 +00:00
# include "ED_sound.h"
2011-01-26 14:18:16 +00:00
# include "ED_util.h"
2009-08-28 11:13:45 +00:00
# include "sound_intern.h"
/******************** open sound operator ********************/
2010-05-29 21:31:57 +00:00
static void open_init ( bContext * C , wmOperator * op )
{
PropertyPointerRNA * pprop ;
2011-08-06 17:57:20 +00:00
2010-05-29 21:31:57 +00:00
op - > customdata = pprop = MEM_callocN ( sizeof ( PropertyPointerRNA ) , " OpenPropertyPointerRNA " ) ;
uiIDContextProperty ( C , & pprop - > ptr , & pprop - > prop ) ;
}
2011-06-23 09:27:56 +00:00
# ifdef WITH_AUDASPACE
2009-08-28 11:13:45 +00:00
static int open_exec ( bContext * C , wmOperator * op )
{
2009-09-12 19:54:39 +00:00
char path [ FILE_MAX ] ;
2009-08-28 11:13:45 +00:00
bSound * sound ;
2010-05-29 21:31:57 +00:00
PropertyPointerRNA * pprop ;
PointerRNA idptr ;
2009-08-28 11:13:45 +00:00
AUD_SoundInfo info ;
2010-06-14 03:52:10 +00:00
RNA_string_get ( op - > ptr , " filepath " , path ) ;
2009-09-12 19:54:39 +00:00
sound = sound_new_file ( CTX_data_main ( C ) , path ) ;
2009-08-28 11:13:45 +00:00
2010-05-29 21:31:57 +00:00
if ( ! op - > customdata )
open_init ( C , op ) ;
2011-08-06 17:57:20 +00:00
2010-02-07 23:41:17 +00:00
if ( sound = = NULL | | sound - > playback_handle = = NULL ) {
2010-05-29 21:31:57 +00:00
if ( op - > customdata ) MEM_freeN ( op - > customdata ) ;
2009-08-28 11:13:45 +00:00
BKE_report ( op - > reports , RPT_ERROR , " Unsupported audio format " ) ;
return OPERATOR_CANCELLED ;
}
2010-02-07 23:41:17 +00:00
info = AUD_getInfo ( sound - > playback_handle ) ;
2009-08-28 11:13:45 +00:00
2010-01-01 05:09:30 +00:00
if ( info . specs . channels = = AUD_CHANNELS_INVALID ) {
2009-08-28 11:13:45 +00:00
sound_delete ( C , sound ) ;
2010-05-29 21:31:57 +00:00
if ( op - > customdata ) MEM_freeN ( op - > customdata ) ;
2009-08-28 11:13:45 +00:00
BKE_report ( op - > reports , RPT_ERROR , " Unsupported audio format " ) ;
return OPERATOR_CANCELLED ;
}
2009-08-29 14:53:00 +00:00
if ( RNA_boolean_get ( op - > ptr , " cache " ) ) {
sound_cache ( sound , 0 ) ;
}
2011-08-06 17:57:20 +00:00
2010-05-29 21:31:57 +00:00
/* hook into UI */
pprop = op - > customdata ;
2011-08-06 17:57:20 +00:00
2010-05-29 21:31:57 +00:00
if ( pprop - > prop ) {
/* when creating new ID blocks, use is already 1, but RNA
* pointer se also increases user , so this compensates it */
sound - > id . us - - ;
2011-08-06 17:57:20 +00:00
2010-05-29 21:31:57 +00:00
RNA_id_pointer_create ( & sound - > id , & idptr ) ;
RNA_property_pointer_set ( & pprop - > ptr , pprop - > prop , idptr ) ;
RNA_property_update ( C , & pprop - > ptr , pprop - > prop ) ;
}
2009-08-29 14:53:00 +00:00
2010-06-03 07:28:47 +00:00
if ( op - > customdata ) MEM_freeN ( op - > customdata ) ;
2009-08-28 11:13:45 +00:00
return OPERATOR_FINISHED ;
}
2011-06-23 09:27:56 +00:00
# else //WITH_AUDASPACE
static int open_exec ( bContext * UNUSED ( C ) , wmOperator * op )
{
BKE_report ( op - > reports , RPT_ERROR , " Compiled without sound support " ) ;
return OPERATOR_CANCELLED ;
}
# endif
2009-08-28 11:13:45 +00:00
static int open_invoke ( bContext * C , wmOperator * op , wmEvent * event )
{
2010-05-29 21:31:57 +00:00
if ( ! RNA_property_is_set ( op - > ptr , " relative_path " ) )
RNA_boolean_set ( op - > ptr , " relative_path " , U . flag & USER_RELPATHS ) ;
2011-08-06 17:57:20 +00:00
2010-06-14 03:52:10 +00:00
if ( RNA_property_is_set ( op - > ptr , " filepath " ) )
2010-05-29 21:31:57 +00:00
return open_exec ( C , op ) ;
2011-08-06 17:57:20 +00:00
2010-05-29 21:31:57 +00:00
open_init ( C , op ) ;
2011-08-06 17:57:20 +00:00
2009-08-28 11:13:45 +00:00
return WM_operator_filesel ( C , op , event ) ;
}
void SOUND_OT_open ( wmOperatorType * ot )
{
/* identifiers */
2009-08-28 12:27:29 +00:00
ot - > name = " Open Sound " ;
2010-02-10 21:15:44 +00:00
ot - > description = " Load a sound file " ;
2009-08-28 11:13:45 +00:00
ot - > idname = " SOUND_OT_open " ;
/* api callbacks */
ot - > exec = open_exec ;
ot - > invoke = open_invoke ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
/* properties */
2010-07-11 09:50:23 +00:00
WM_operator_properties_filesel ( ot , FOLDERFILE | SOUNDFILE | MOVIEFILE , FILE_SPECIAL , FILE_OPENFILE , WM_FILESEL_FILEPATH | WM_FILESEL_RELPATH ) ;
2009-08-29 14:53:00 +00:00
RNA_def_boolean ( ot - > srna , " cache " , FALSE , " Cache " , " Cache the sound in memory. " ) ;
2009-08-28 11:13:45 +00:00
}
2011-08-06 17:57:20 +00:00
/******************** mixdown operator ********************/
static int mixdown_exec ( bContext * C , wmOperator * op )
{
char path [ FILE_MAX ] ;
char filename [ FILE_MAX ] ;
Scene * scene ;
Main * bmain ;
int bitrate , accuracy ;
AUD_DeviceSpecs specs ;
AUD_Container container ;
AUD_Codec codec ;
const char * result ;
RNA_string_get ( op - > ptr , " filepath " , path ) ;
bitrate = RNA_int_get ( op - > ptr , " bitrate " ) * 1000 ;
accuracy = RNA_int_get ( op - > ptr , " accuracy " ) ;
specs . format = RNA_enum_get ( op - > ptr , " format " ) ;
container = RNA_enum_get ( op - > ptr , " container " ) ;
codec = RNA_enum_get ( op - > ptr , " codec " ) ;
scene = CTX_data_scene ( C ) ;
bmain = CTX_data_main ( C ) ;
specs . channels = scene - > r . ffcodecdata . audio_channels ;
specs . rate = scene - > r . ffcodecdata . audio_mixrate ;
BLI_strncpy ( filename , path , sizeof ( filename ) ) ;
BLI_path_abs ( filename , bmain - > name ) ;
result = AUD_mixdown ( scene - > sound_scene , SFRA * specs . rate / FPS , ( EFRA - SFRA ) * specs . rate / FPS ,
accuracy , filename , specs , container , codec , bitrate ) ;
if ( result )
{
BKE_report ( op - > reports , RPT_ERROR , result ) ;
return OPERATOR_CANCELLED ;
}
return OPERATOR_FINISHED ;
}
static int mixdown_invoke ( bContext * C , wmOperator * op , wmEvent * event )
{
if ( ! RNA_property_is_set ( op - > ptr , " relative_path " ) )
RNA_boolean_set ( op - > ptr , " relative_path " , U . flag & USER_RELPATHS ) ;
if ( RNA_property_is_set ( op - > ptr , " filepath " ) )
return mixdown_exec ( C , op ) ;
return WM_operator_filesel ( C , op , event ) ;
}
static int mixdown_draw_check_prop ( PropertyRNA * prop )
{
const char * prop_id = RNA_property_identifier ( prop ) ;
return ! ( strcmp ( prop_id , " filepath " ) = = 0 | |
strcmp ( prop_id , " directory " ) = = 0 | |
strcmp ( prop_id , " filename " ) = = 0
) ;
}
static void mixdown_draw ( bContext * C , wmOperator * op )
{
static EnumPropertyItem pcm_format_items [ ] = {
{ AUD_FORMAT_U8 , " U8 " , 0 , " U8 " , " 8 bit unsigned " } ,
{ AUD_FORMAT_S16 , " S16 " , 0 , " S16 " , " 16 bit signed " } ,
# ifdef WITH_SNDFILE
{ AUD_FORMAT_S24 , " S24 " , 0 , " S24 " , " 24 bit signed " } ,
# endif
{ AUD_FORMAT_S32 , " S32 " , 0 , " S32 " , " 32 bit signed " } ,
{ AUD_FORMAT_FLOAT32 , " F32 " , 0 , " F32 " , " 32 bit floating point " } ,
{ AUD_FORMAT_FLOAT64 , " F64 " , 0 , " F64 " , " 64 bit floating point " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
static EnumPropertyItem mp3_format_items [ ] = {
{ AUD_FORMAT_S16 , " S16 " , 0 , " S16 " , " 16 bit signed " } ,
{ AUD_FORMAT_S32 , " S32 " , 0 , " S32 " , " 32 bit signed " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
static EnumPropertyItem ac3_format_items [ ] = {
{ AUD_FORMAT_S16 , " S16 " , 0 , " S16 " , " 16 bit signed " } ,
{ AUD_FORMAT_FLOAT32 , " F32 " , 0 , " F32 " , " 32 bit floating point " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
# ifdef WITH_SNDFILE
static EnumPropertyItem flac_format_items [ ] = {
{ AUD_FORMAT_S16 , " S16 " , 0 , " S16 " , " 16 bit signed " } ,
{ AUD_FORMAT_S24 , " S24 " , 0 , " S24 " , " 24 bit signed " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
# endif
static EnumPropertyItem all_codec_items [ ] = {
{ AUD_CODEC_AAC , " AAC " , 0 , " AAC " , " Advanced Audio Coding " } ,
{ AUD_CODEC_AC3 , " AC3 " , 0 , " AC3 " , " Dolby Digital ATRAC 3 " } ,
{ AUD_CODEC_FLAC , " FLAC " , 0 , " FLAC " , " Free Lossless Audio Codec " } ,
{ AUD_CODEC_MP2 , " MP2 " , 0 , " MP2 " , " MPEG-1 Audio Layer II " } ,
{ AUD_CODEC_MP3 , " MP3 " , 0 , " MP3 " , " MPEG-2 Audio Layer III " } ,
{ AUD_CODEC_PCM , " PCM " , 0 , " PCM " , " Pulse Code Modulation (RAW) " } ,
{ AUD_CODEC_VORBIS , " VORBIS " , 0 , " Vorbis " , " Xiph.Org Vorbis Codec " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
static EnumPropertyItem ogg_codec_items [ ] = {
{ AUD_CODEC_FLAC , " FLAC " , 0 , " FLAC " , " Free Lossless Audio Codec " } ,
{ AUD_CODEC_VORBIS , " VORBIS " , 0 , " Vorbis " , " Xiph.Org Vorbis Codec " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
uiLayout * layout = op - > layout ;
wmWindowManager * wm = CTX_wm_manager ( C ) ;
PointerRNA ptr ;
PropertyRNA * prop_format ;
PropertyRNA * prop_codec ;
PropertyRNA * prop_bitrate ;
AUD_Container container = RNA_enum_get ( op - > ptr , " container " ) ;
AUD_Codec codec = RNA_enum_get ( op - > ptr , " codec " ) ;
prop_format = RNA_struct_find_property ( op - > ptr , " format " ) ;
prop_codec = RNA_struct_find_property ( op - > ptr , " codec " ) ;
prop_bitrate = RNA_struct_find_property ( op - > ptr , " bitrate " ) ;
RNA_def_property_clear_flag ( prop_bitrate , PROP_HIDDEN ) ;
RNA_def_property_flag ( prop_codec , PROP_HIDDEN ) ;
RNA_def_property_flag ( prop_format , PROP_HIDDEN ) ;
switch ( container )
{
case AUD_CONTAINER_AC3 :
RNA_def_property_clear_flag ( prop_format , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_format , ac3_format_items ) ;
RNA_def_property_enum_items ( prop_codec , all_codec_items ) ;
RNA_enum_set ( op - > ptr , " codec " , AUD_CODEC_AC3 ) ;
break ;
case AUD_CONTAINER_FLAC :
RNA_def_property_flag ( prop_bitrate , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_codec , all_codec_items ) ;
RNA_enum_set ( op - > ptr , " codec " , AUD_CODEC_FLAC ) ;
# ifdef WITH_SNDFILE
RNA_def_property_clear_flag ( prop_format , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_format , flac_format_items ) ;
# else
RNA_enum_set ( op - > ptr , " format " , AUD_FORMAT_S16 ) ;
# endif
break ;
case AUD_CONTAINER_MATROSKA :
RNA_def_property_clear_flag ( prop_codec , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_codec , all_codec_items ) ;
switch ( codec )
{
case AUD_CODEC_AAC :
RNA_enum_set ( op - > ptr , " format " , AUD_FORMAT_S16 ) ;
break ;
case AUD_CODEC_AC3 :
RNA_def_property_enum_items ( prop_format , ac3_format_items ) ;
RNA_def_property_clear_flag ( prop_format , PROP_HIDDEN ) ;
break ;
case AUD_CODEC_FLAC :
RNA_def_property_flag ( prop_bitrate , PROP_HIDDEN ) ;
RNA_enum_set ( op - > ptr , " format " , AUD_FORMAT_S16 ) ;
break ;
case AUD_CODEC_MP2 :
RNA_enum_set ( op - > ptr , " format " , AUD_FORMAT_S16 ) ;
break ;
case AUD_CODEC_MP3 :
RNA_def_property_enum_items ( prop_format , mp3_format_items ) ;
RNA_def_property_clear_flag ( prop_format , PROP_HIDDEN ) ;
break ;
case AUD_CODEC_PCM :
RNA_def_property_flag ( prop_bitrate , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_format , pcm_format_items ) ;
RNA_def_property_clear_flag ( prop_format , PROP_HIDDEN ) ;
break ;
case AUD_CODEC_VORBIS :
RNA_enum_set ( op - > ptr , " format " , AUD_FORMAT_S16 ) ;
break ;
}
break ;
case AUD_CONTAINER_MP2 :
RNA_enum_set ( op - > ptr , " format " , AUD_FORMAT_S16 ) ;
RNA_enum_set ( op - > ptr , " codec " , AUD_CODEC_MP2 ) ;
RNA_def_property_enum_items ( prop_codec , all_codec_items ) ;
break ;
case AUD_CONTAINER_MP3 :
RNA_def_property_clear_flag ( prop_format , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_format , mp3_format_items ) ;
RNA_def_property_enum_items ( prop_codec , all_codec_items ) ;
RNA_enum_set ( op - > ptr , " codec " , AUD_CODEC_MP3 ) ;
break ;
case AUD_CONTAINER_OGG :
RNA_def_property_clear_flag ( prop_codec , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_codec , ogg_codec_items ) ;
RNA_enum_set ( op - > ptr , " format " , AUD_FORMAT_S16 ) ;
break ;
case AUD_CONTAINER_WAV :
RNA_def_property_flag ( prop_bitrate , PROP_HIDDEN ) ;
RNA_def_property_clear_flag ( prop_format , PROP_HIDDEN ) ;
RNA_def_property_enum_items ( prop_format , pcm_format_items ) ;
RNA_def_property_enum_items ( prop_codec , all_codec_items ) ;
RNA_enum_set ( op - > ptr , " codec " , AUD_CODEC_PCM ) ;
break ;
}
RNA_pointer_create ( & wm - > id , op - > type - > srna , op - > properties , & ptr ) ;
/* main draw call */
uiDefAutoButsRNA ( layout , & ptr , mixdown_draw_check_prop , ' \0 ' ) ;
}
void SOUND_OT_mixdown ( wmOperatorType * ot )
{
static EnumPropertyItem format_items [ ] = {
{ AUD_FORMAT_U8 , " U8 " , 0 , " U8 " , " 8 bit unsigned " } ,
{ AUD_FORMAT_S16 , " S16 " , 0 , " S16 " , " 16 bit signed " } ,
{ AUD_FORMAT_S24 , " S24 " , 0 , " S24 " , " 24 bit signed " } ,
{ AUD_FORMAT_S32 , " S32 " , 0 , " S32 " , " 32 bit signed " } ,
{ AUD_FORMAT_FLOAT32 , " F32 " , 0 , " F32 " , " 32 bit floating point " } ,
{ AUD_FORMAT_FLOAT64 , " F64 " , 0 , " F64 " , " 64 bit floating point " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
static EnumPropertyItem container_items [ ] = {
# ifdef WITH_FFMPEG
{ AUD_CONTAINER_AC3 , " AC3 " , 0 , " ac3 " , " Dolby Digital ATRAC 3 " } ,
# endif
{ AUD_CONTAINER_FLAC , " FLAC " , 0 , " flac " , " Free Lossless Audio Codec " } ,
# ifdef WITH_FFMPEG
{ AUD_CONTAINER_MATROSKA , " MATROSKA " , 0 , " mkv " , " Matroska " } ,
{ AUD_CONTAINER_MP2 , " MP2 " , 0 , " mp2 " , " MPEG-1 Audio Layer II " } ,
{ AUD_CONTAINER_MP3 , " MP3 " , 0 , " mp3 " , " MPEG-2 Audio Layer III " } ,
# endif
{ AUD_CONTAINER_OGG , " OGG " , 0 , " ogg " , " Xiph.Org Ogg Container " } ,
{ AUD_CONTAINER_WAV , " WAV " , 0 , " wav " , " Waveform Audio File Format " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
static EnumPropertyItem codec_items [ ] = {
# ifdef WITH_FFMPEG
{ AUD_CODEC_AAC , " AAC " , 0 , " AAC " , " Advanced Audio Coding " } ,
{ AUD_CODEC_AC3 , " AC3 " , 0 , " AC3 " , " Dolby Digital ATRAC 3 " } ,
# endif
{ AUD_CODEC_FLAC , " FLAC " , 0 , " FLAC " , " Free Lossless Audio Codec " } ,
# ifdef WITH_FFMPEG
{ AUD_CODEC_MP2 , " MP2 " , 0 , " MP2 " , " MPEG-1 Audio Layer II " } ,
{ AUD_CODEC_MP3 , " MP3 " , 0 , " MP3 " , " MPEG-2 Audio Layer III " } ,
# endif
{ AUD_CODEC_PCM , " PCM " , 0 , " PCM " , " Pulse Code Modulation (RAW) " } ,
{ AUD_CODEC_VORBIS , " VORBIS " , 0 , " Vorbis " , " Xiph.Org Vorbis Codec " } ,
{ 0 , NULL , 0 , NULL , NULL } } ;
/* identifiers */
ot - > name = " Mixdown " ;
ot - > description = " Mixes the scene's audio to a sound file " ;
ot - > idname = " SOUND_OT_mixdown " ;
/* api callbacks */
ot - > exec = mixdown_exec ;
ot - > invoke = mixdown_invoke ;
ot - > ui = mixdown_draw ;
/* flags */
ot - > flag = OPTYPE_REGISTER ;
/* properties */
WM_operator_properties_filesel ( ot , FOLDERFILE | SOUNDFILE , FILE_SPECIAL , FILE_SAVE , WM_FILESEL_FILEPATH ) ;
RNA_def_int ( ot - > srna , " accuracy " , 1024 , 1 , 16777216 , " Accuracy " , " Sample accuracy. Important for animation data. The lower the value, the more accurate. " , 1 , 16777216 ) ;
RNA_def_enum ( ot - > srna , " container " , container_items , AUD_CONTAINER_FLAC , " Container " , " File format " ) ;
RNA_def_enum ( ot - > srna , " codec " , codec_items , AUD_CODEC_FLAC , " Codec " , " Audio Codec " ) ;
RNA_def_enum ( ot - > srna , " format " , format_items , AUD_FORMAT_S16 , " Format " , " Sample format " ) ;
RNA_def_int ( ot - > srna , " bitrate " , 192 , 32 , 512 , " Bitrate " , " Bitrate in kbit/s " , 32 , 512 ) ;
}
2009-08-28 11:13:45 +00:00
/* ******************************************************* */
2009-08-28 21:47:05 +00:00
static int sound_poll ( bContext * C )
{
Editing * ed = CTX_data_scene ( C ) - > ed ;
2009-08-28 22:04:37 +00:00
if ( ! ed | | ! ed - > act_seq | | ed - > act_seq - > type ! = SEQ_SOUND )
2009-08-28 21:47:05 +00:00
return 0 ;
return 1 ;
}
/********************* pack operator *********************/
static int pack_exec ( bContext * C , wmOperator * op )
{
Editing * ed = CTX_data_scene ( C ) - > ed ;
bSound * sound ;
if ( ! ed | | ! ed - > act_seq | | ed - > act_seq - > type ! = SEQ_SOUND )
return OPERATOR_CANCELLED ;
sound = ed - > act_seq - > sound ;
if ( ! sound | | sound - > packedfile )
return OPERATOR_CANCELLED ;
sound - > packedfile = newPackedFile ( op - > reports , sound - > name ) ;
2010-10-17 09:01:37 +00:00
sound_load ( CTX_data_main ( C ) , sound ) ;
2009-08-28 21:47:05 +00:00
return OPERATOR_FINISHED ;
}
2011-02-14 17:55:27 +00:00
static void SOUND_OT_pack ( wmOperatorType * ot )
2009-08-28 21:47:05 +00:00
{
/* identifiers */
ot - > name = " Pack Sound " ;
2010-02-10 21:15:44 +00:00
ot - > description = " Pack the sound into the current blend file " ;
2009-08-28 21:47:05 +00:00
ot - > idname = " SOUND_OT_pack " ;
/* api callbacks */
ot - > exec = pack_exec ;
ot - > poll = sound_poll ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
}
/********************* unpack operator *********************/
2011-01-26 14:18:16 +00:00
static int sound_unpack_exec ( bContext * C , wmOperator * op )
2009-08-28 21:47:05 +00:00
{
int method = RNA_enum_get ( op - > ptr , " method " ) ;
2011-02-07 01:13:21 +00:00
bSound * sound = NULL ;
2009-08-28 21:47:05 +00:00
2011-01-26 14:18:16 +00:00
/* find the suppplied image by name */
if ( RNA_property_is_set ( op - > ptr , " id " ) ) {
2011-04-19 06:59:49 +00:00
char sndname [ MAX_ID_NAME - 2 ] ;
2011-01-26 14:18:16 +00:00
RNA_string_get ( op - > ptr , " id " , sndname ) ;
sound = BLI_findstring ( & CTX_data_main ( C ) - > sound , sndname , offsetof ( ID , name ) + 2 ) ;
}
2009-08-28 21:47:05 +00:00
if ( ! sound | | ! sound - > packedfile )
return OPERATOR_CANCELLED ;
if ( G . fileflags & G_AUTOPACK )
BKE_report ( op - > reports , RPT_WARNING , " AutoPack is enabled, so image will be packed again on file save. " ) ;
2010-11-13 13:44:45 +00:00
unpackSound ( CTX_data_main ( C ) , op - > reports , sound , method ) ;
2009-08-28 21:47:05 +00:00
return OPERATOR_FINISHED ;
}
2011-01-26 14:18:16 +00:00
static int sound_unpack_invoke ( bContext * C , wmOperator * op , wmEvent * UNUSED ( event ) )
2009-08-28 21:47:05 +00:00
{
Editing * ed = CTX_data_scene ( C ) - > ed ;
bSound * sound ;
2011-01-26 14:18:16 +00:00
if ( RNA_property_is_set ( op - > ptr , " id " ) )
return sound_unpack_exec ( C , op ) ;
2009-08-28 21:47:05 +00:00
if ( ! ed | | ! ed - > act_seq | | ed - > act_seq - > type ! = SEQ_SOUND )
return OPERATOR_CANCELLED ;
sound = ed - > act_seq - > sound ;
if ( ! sound | | ! sound - > packedfile )
return OPERATOR_CANCELLED ;
if ( G . fileflags & G_AUTOPACK )
BKE_report ( op - > reports , RPT_WARNING , " AutoPack is enabled, so image will be packed again on file save. " ) ;
2011-04-18 14:24:36 +00:00
unpack_menu ( C , " SOUND_OT_unpack " , sound - > id . name + 2 , sound - > name , " sounds " , sound - > packedfile ) ;
2009-08-28 21:47:05 +00:00
return OPERATOR_FINISHED ;
}
2011-02-14 17:55:27 +00:00
static void SOUND_OT_unpack ( wmOperatorType * ot )
2009-08-28 21:47:05 +00:00
{
/* identifiers */
ot - > name = " Unpack Sound " ;
2010-02-10 21:15:44 +00:00
ot - > description = " Unpack the sound to the samples filename " ;
2009-08-28 21:47:05 +00:00
ot - > idname = " SOUND_OT_unpack " ;
/* api callbacks */
2011-01-26 14:18:16 +00:00
ot - > exec = sound_unpack_exec ;
ot - > invoke = sound_unpack_invoke ;
2009-08-28 21:47:05 +00:00
ot - > poll = sound_poll ;
/* flags */
ot - > flag = OPTYPE_REGISTER | OPTYPE_UNDO ;
/* properties */
RNA_def_enum ( ot - > srna , " method " , unpack_method_items , PF_USE_LOCAL , " Method " , " How to unpack. " ) ;
2011-04-19 06:59:49 +00:00
RNA_def_string ( ot - > srna , " id " , " " , MAX_ID_NAME - 2 , " Sound Name " , " Sound datablock name to unpack. " ) ; /* XXX, weark!, will fail with library, name collisions */
2009-08-28 21:47:05 +00:00
}
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
/* ******************************************************* */
static int update_animation_flags_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
Sequence * seq ;
Scene * scene = CTX_data_scene ( C ) ;
struct FCurve * fcu ;
char driven ;
SEQ_BEGIN ( scene - > ed , seq ) {
fcu = id_data_find_fcurve ( & scene - > id , seq , & RNA_Sequence , " volume " , 0 , & driven ) ;
if ( fcu | | driven )
seq - > flag | = SEQ_AUDIO_VOLUME_ANIMATED ;
else
seq - > flag & = ~ SEQ_AUDIO_VOLUME_ANIMATED ;
fcu = id_data_find_fcurve ( & scene - > id , seq , & RNA_Sequence , " pitch " , 0 , & driven ) ;
if ( fcu | | driven )
seq - > flag | = SEQ_AUDIO_PITCH_ANIMATED ;
else
seq - > flag & = ~ SEQ_AUDIO_PITCH_ANIMATED ;
fcu = id_data_find_fcurve ( & scene - > id , seq , & RNA_Sequence , " pan " , 0 , & driven ) ;
if ( fcu | | driven )
seq - > flag | = SEQ_AUDIO_PAN_ANIMATED ;
else
seq - > flag & = ~ SEQ_AUDIO_PAN_ANIMATED ;
}
SEQ_END
fcu = id_data_find_fcurve ( & scene - > id , scene , & RNA_Scene , " audio_volume " , 0 , & driven ) ;
if ( fcu | | driven )
scene - > audio . flag | = AUDIO_VOLUME_ANIMATED ;
else
scene - > audio . flag & = ~ AUDIO_VOLUME_ANIMATED ;
return OPERATOR_FINISHED ;
}
void SOUND_OT_update_animation_flags ( wmOperatorType * ot )
{
/* identifiers */
ot - > name = " Update animation " ;
ot - > description = " Update animation flags " ;
ot - > idname = " SOUND_OT_update_animation_flags " ;
/* api callbacks */
ot - > exec = update_animation_flags_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER ;
}
/* ******************************************************* */
static int bake_animation_exec ( bContext * C , wmOperator * UNUSED ( op ) )
{
Main * bmain = CTX_data_main ( C ) ;
Scene * scene = CTX_data_scene ( C ) ;
int oldfra = scene - > r . cfra ;
int cfra ;
update_animation_flags_exec ( C , NULL ) ;
for ( cfra = scene - > r . sfra ; cfra < = scene - > r . efra ; cfra + + )
{
scene - > r . cfra = cfra ;
scene_update_for_newframe ( bmain , scene , scene - > lay ) ;
}
scene - > r . cfra = oldfra ;
scene_update_for_newframe ( bmain , scene , scene - > lay ) ;
return OPERATOR_FINISHED ;
}
void SOUND_OT_bake_animation ( wmOperatorType * ot )
{
/* identifiers */
2011-08-01 11:44:20 +00:00
ot - > name = " Update animation cache " ;
ot - > description = " Updates the audio animation cache so that it's up to date " ;
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
ot - > idname = " SOUND_OT_bake_animation " ;
/* api callbacks */
ot - > exec = bake_animation_exec ;
/* flags */
ot - > flag = OPTYPE_REGISTER ;
}
2009-08-28 21:47:05 +00:00
/* ******************************************************* */
2009-08-28 12:27:29 +00:00
void ED_operatortypes_sound ( void )
2009-08-28 11:13:45 +00:00
{
WM_operatortype_append ( SOUND_OT_open ) ;
2011-08-06 17:57:20 +00:00
WM_operatortype_append ( SOUND_OT_mixdown ) ;
2009-08-28 21:47:05 +00:00
WM_operatortype_append ( SOUND_OT_pack ) ;
WM_operatortype_append ( SOUND_OT_unpack ) ;
3D Audio GSoC:
Implemented basic audio animation.
* AnimatableProperty: Propper cache writing and spline interpolation for reading (the solution for stair steps in audio animation)
* Animatable properties so far are: volume, pitch, panning
* Users note: Changing the pitch of a sound results in wrong seeking, due to the resulting playback length difference.
* Users note: Panning only works for mono sources, values are in the range [-2..2], this basically controls the angle of the sound, 0 is front, -1 left, 1 right and 2 and -2 are back. Typical stereo panning only supports [-1..1].
* Disabled animation of audio related ffmpeg output parameters.
* Scene Audio Panel: 3D Listener settings also for Renderer, new Volume property (animatable!), Update/Bake buttons for animation problems, moved sampling rate and channel count here
2011-07-28 13:58:59 +00:00
WM_operatortype_append ( SOUND_OT_update_animation_flags ) ;
WM_operatortype_append ( SOUND_OT_bake_animation ) ;
2009-08-28 11:13:45 +00:00
}