Limit mode creation to supported modes.

We did no real error checking to see if a mode is supported when it
 is created.
This patch implements checks for Jean-Marc's rules:
1) A mode must have frames at least 1ms in length (no more than
    1000 per second).
2) A mode must have shorts of at most 3.33 ms (at least 300 per
    second).
It also adds error checking to dump_modes so we report the error
 instead of crashing when we fail to create a mode.
diff --git a/libcelt/modes.c b/libcelt/modes.c
index 259a49b..6414d2f 100644
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -331,7 +331,35 @@
          *error = CELT_BAD_ARG;
       return NULL;
    }
-   
+   /* Frames of less than 1ms are not supported. */
+   if ((celt_int32)frame_size*1000 < Fs)
+   {
+      if (error)
+         *error = CELT_INVALID_MODE;
+      return NULL;
+   }
+
+   if ((celt_int32)frame_size*75 >= Fs && (frame_size%16)==0)
+   {
+     LM = 3;
+   } else if ((celt_int32)frame_size*150 >= Fs && (frame_size%8)==0)
+   {
+     LM = 2;
+   } else if ((celt_int32)frame_size*300 >= Fs && (frame_size%4)==0)
+   {
+     LM = 1;
+   } else if ((celt_int32)frame_size*300 <= Fs)
+   {
+     LM = 0;
+   }
+   /* Shorts longer than 3.3ms are not supported. */
+   else
+   {
+      if (error)
+         *error = CELT_INVALID_MODE;
+      return NULL;
+   }
+
    mode = celt_alloc(sizeof(CELTMode));
    if (mode==NULL)
       goto failure;
@@ -366,20 +394,6 @@
       mode->preemph[3] =  QCONST16(1.f, 13);
    }
 
-   if ((celt_int32)frame_size*75 >= Fs && (frame_size%16)==0)
-   {
-     LM = 3;
-   } else if ((celt_int32)frame_size*150 >= Fs && (frame_size%8)==0)
-   {
-     LM = 2;
-   } else if ((celt_int32)frame_size*300 >= Fs && (frame_size%4)==0)
-   {
-     LM = 1;
-   } else
-   {
-     LM = 0;
-   }
-
    mode->maxLM = LM;
    mode->nbShortMdcts = 1<<LM;
    mode->shortMdctSize = frame_size/mode->nbShortMdcts;